题目链接:http://lightoj.com/volume_showproblem.php?problem=1220

题意:已知 x=b中的 x 求最大的 p,其中 x b p 都为整数

x = (p1a1*p2a2*p3a3*...*pkak), pi为素数;则结果就是gcd(a1, a2, a3,...,ak);

当x为负数时,要把ans缩小为奇数;

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = 1e6+;
const double eps = 1e-; int f[N], p[N], k = ;
void Init()
{
for(int i=; i<N; i++)
{
if(!f[i]) p[k++] = i;
for(int j=i; j<N; j+=i)
f[i] = ;
}
} int gcd(int a, int b)
{
return b == ? a : gcd(b, a%b);
} int cnt[N]; int main()
{
Init(); int T, t = ; scanf("%d", &T); while(T--)
{
LL n;
int flag = ; scanf("%lld", &n); if(n < )
{
n = -n;
flag = ;
} int ans = ; memset(cnt, , sizeof(cnt)); for(int i=; i<k && (LL)p[i]*p[i]<=n; i++)
{
while(n%p[i] == )
{
cnt[i]++;
n /= p[i];
}
if(ans == && cnt[i])
ans = cnt[i];
else if(cnt[i])
ans = gcd(cnt[i], ans);
} if(n > || ans == )
ans = ; if(flag)///负数,结果一定是奇数;
{
while(ans% == )
ans /= ;
}
printf("Case %d: %d\n", t++, ans);
}
return ;
}
/*
-1000000
1 3
1
*/

LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)的更多相关文章

  1. LightOJ 1220 Mysterious Bacteria(唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1220 Mysterious Bacteria Time Limit:500MS     Memo ...

  2. LightOj 1220 Mysterious Bacteria

    题目大意: 给出一个x,求满足x = b^p,p最大是多少? 解题思路: x可以表示为:x = p1^e1 * p2^e2 * p3^e3 ....... * pn^en. p = gcd (e1,e ...

  3. LightOJ 1220 Mysterious Bacteria 水题

    暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...

  4. UVA 10780 Again Prime? No Time. 分解质因子

    The problem statement is very easy. Given a number n you have to determine the largest power of m,no ...

  5. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  6. hdu6237 分解质因子

    题意:给一堆石子,每次移动一颗到另一堆,要求最小次数使得,所有石子数gcd>1 题解:枚举所有质因子,然后找次数最小的那一个,统计次数时,我们可以事先记录下每堆石子余质因子 的和,对所有石子取余 ...

  7. NYOJ-476谁是英雄,分解质因子求约数个数!

    谁是英雄 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 十个数学家(编号0-9)乘气球飞行在太平洋上空.当横越赤道时,他们决定庆祝一下这一壮举.于是他们开了一瓶香槟.不 ...

  8. Codeforces Round #828 (Div. 3) E2. Divisible Numbers (分解质因子,dfs判断x,y)

    题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a ...

  9. HDU 4135 Co-prime (容斥+分解质因子)

    <题目链接> 题目大意: 给定区间[A,B](1 <= A <= B <= 10 15)和N(1 <=N <= 10 9),求出该区间中与N互质的数的个数. ...

随机推荐

  1. Code Rush插件

    code rush 是微软推出的一款VS2008上的插件.他有强大的文件和代码导航功能,易于访问的重构和代码创建功能.一组编辑器.选择.剪贴板工具等. 教程链接 http://www.devexpre ...

  2. Problem to create "New Database Diagram" in Microsoft SQL Server Management Studio for SQL Server 2012

    Error: when click "New Database Diagram", a error popped up and said "Attempted to re ...

  3. java中的IO操作总结

    一.InputStream重用技巧(利用ByteArrayOutputStream) 对同一个InputStream对象进行使用多次. 比如,客户端从服务器获取数据 ,利用HttpURLConnect ...

  4. BZOJ 3339 & 莫队+"所谓的暴力"

    题意: 给一段数字序列,求一段区间内未出现的最小自然数. SOL: 框架显然用莫队.因为它兹瓷离线. 然而在统计上我打了线段树...用&维护的结点...400w的线段树...然后二分查找... ...

  5. Android Fragment 生命周期及其API使用(建议使用自定义View替换Fragment)

    我为什么不主张使用Fragment Fragment:( Fragment就相当于一个有生命周期的View,它的生命周期被所在的Activity的生命周期管理 ) 生命周期回调说明: onAttach ...

  6. 使用TCMalloc优化OpenResty

    1.安装依赖包 yum -y install wget gcc gcc-c++ -y 2.安装libunwind库可以从http://ftp.twaren.net/Unix/NonGNU//libun ...

  7. js,html,css注释大集合

    1.js注释: 单行注释,在注释内容前加符号 “//” <script type="text/javascript"> document.write("单行注 ...

  8. 【CodeVS】 p1225 八数码难题

    题目描述 Description Yours和zero在研究A*启发式算法.拿到一道经典的A*问题,但是他们不会做,请你帮他们.问题描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字 ...

  9. 硬盘分区工具gparted使用

    一.介绍 GParted是一款linux下的功能非常强大的分区工具,和windows下的‘分区魔术师’类似,操作和显示上也很相似.GParted可以方便的创建.删除分区,也可以调整分区的大小和移动分区 ...

  10. 实用的Bootstrap的扩展和插件集合

    bootstrap插件 http://www.missyuan.net/school/other_2014/other_16472.html http://www.oschina.net/news/5 ...