LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1220
题意:已知 x=bp 中的 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)的更多相关文章
- LightOJ 1220 Mysterious Bacteria(唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1220 Mysterious Bacteria Time Limit:500MS Memo ...
- LightOj 1220 Mysterious Bacteria
题目大意: 给出一个x,求满足x = b^p,p最大是多少? 解题思路: x可以表示为:x = p1^e1 * p2^e2 * p3^e3 ....... * pn^en. p = gcd (e1,e ...
- LightOJ 1220 Mysterious Bacteria 水题
暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...
- 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 ...
- 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,求满 ...
- hdu6237 分解质因子
题意:给一堆石子,每次移动一颗到另一堆,要求最小次数使得,所有石子数gcd>1 题解:枚举所有质因子,然后找次数最小的那一个,统计次数时,我们可以事先记录下每堆石子余质因子 的和,对所有石子取余 ...
- NYOJ-476谁是英雄,分解质因子求约数个数!
谁是英雄 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 十个数学家(编号0-9)乘气球飞行在太平洋上空.当横越赤道时,他们决定庆祝一下这一壮举.于是他们开了一瓶香槟.不 ...
- 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 ...
- HDU 4135 Co-prime (容斥+分解质因子)
<题目链接> 题目大意: 给定区间[A,B](1 <= A <= B <= 10 15)和N(1 <=N <= 10 9),求出该区间中与N互质的数的个数. ...
随机推荐
- Nginx设置Js、Css等静态文件的缓存过期时间
location ~.*\.(js|css|html|png|jpg)$ { expires 3d; } expires 3d; //表示缓存3天 expires 3h; //表示缓存3小 ...
- NOI模拟赛Day5
T1 有and,xor,or三种操作,每个人手中一个数,求和左边进行某一种运算的最大值,当t==2时,还需要求最大值的个数. test1 20% n<=1000 O(n^2)暴力 test2 2 ...
- SQL Server2008清空日志文件
USE[master] GO ALTER DATABASE mydbname SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE mydbname S ...
- Oracle临时表GLOBAL TEMPORARY TABLE
临时表:像普通表一样,有结构,但是对数据的管理上不一样,临时表存储事务或会话的中间结果集,临时表中保存的数据只对当前 会话可见,所有会话都看不到其他会话的数据,即使其他会话提交了,也看不到.临时表不存 ...
- CentOS评估磁盘I/O性能读写极限测试
用一个fio工具 安装 yum -y install fio 二,FIO用法: 随机读:fio -direct=1 -iodepth 1 -thread -rw=randread -ioengine ...
- MVVM deep dive
You can get a different instance each time by passing a different key to the GetInstance method. How ...
- mysql 主从同步原理
Replication 线程 Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql instance(我们 ...
- CAS单点登录中文用户名乱码问题
CAS单点登录中文用户名乱码问题,有两种情况 1. CAS server乱码 即在向server端提交用户名和密码时,发生了乱码,解决方法是: 打开WEB-INF/web.xml,在其它的Filter ...
- Odoo 动态设置树形视图列表中的字段
依赖第三方模块实现,实现效果图如下: 原模块只有9.0版本 ,今改成了8.0版本. git地址见群内公告.
- 使用webbench对不同的web服务器进行压力测试
1.webbench在linux下的安装步骤,如果安装过程失败,请检查当前用户的执行权限,如果报找不到某个目录的错,请自行创建指定的目录: #wget http://home.tiscali.cz/~ ...