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互质的数的个数. ...
随机推荐
- Leetcode Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- topcoder SRM 622 DIV2 FibonacciDiv2
关于斐波那契数列,由于数据量比较小, 直接打表了,代码写的比较戳 #include <iostream> #include <vector> #include <algo ...
- ACM: 限时训练题解-Runtime Error-二分查找
Runtime Error Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...
- C#中的IComparable 和 IComparer 接口,实现列表中的对象比较和排序
借豆瓣某博主的话先对这两个接口进行一个解释: IComparable在要比较的对象的类中实现,可以比较该对象和另一个对象 IComparer在一个单独的类中实现,可以比较任意两个对象. 如果已经支持 ...
- [BZOJ2791][Poi2012]Rendezvous
2791: [Poi2012]Rendezvous Time Limit: 25 Sec Memory Limit: 128 MBSubmit: 95 Solved: 71[Submit][Sta ...
- 淘宝UED上关于chrome的transition闪烁问题的解决方案
前段时间,有同事和会员反馈使用Chrome访问淘宝首页会出现画面闪动的现象,但是我在Mac和Win下面的Chrome都无法重现这个问题,后来重装了一遍Win7下的Chrome Beta版本,终于重现了 ...
- POJ 1321 简单dfs
1.POJ 1321 棋盘问题 2.总结: 题意:给定棋盘上放k个棋子,要求同行同列都不重. #include<iostream> #include<cstring> #in ...
- GO语言练习:实现最简单的http helloword 服务器
用Go语言实现一个最简单的http服务器端,主要用到了package io, log, net/http 这个3个库. 用到的函数包括: http.Handle() http.HandlerFunc( ...
- javascrit2.0完全参考手册(第二版) 第2章第2节 语言特性
脚本执行顺序 js代码是按照它们在html中出现的顺序一行一行被解释的.这表明把函数定义和变量声明放到<head>中会很好.这保证了函数的代码和事件相关的处理程序不会立即执行. 大 ...
- Oracle 客户端免安装数据库连接
PLSQL Developer 连接数据库需要安装Oracle客户端,在这里介绍一种Oracle客户端解压式安装,而不是exe安装. 安装步骤: 1:确定客户端安装所在主机的系统位数 2:选择正确的客 ...