# lightoj 1220

103人阅读 评论(0)

1220 - Mysterious Bacteria
 Time Limit: 0.5 second(s) Memory Limit: 32 MB

Dr. Mob has just discovered a Deathly Bacteria. He named itRC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly xdays. Now RC-01 produces exactly p new deadly Bacteria where x = bp(where b, p are integers). More generally, x is a perfect pthpower. Given the lifetime x of a mother RC-01 you are to determine themaximum number of new RC-01 which can be produced by the mother RC-01.

# Input

Input starts with an integer T (≤ 50),denoting the number of test cases.

Each case starts with a line containing an integer x.You can assume that x will have magnitude at least 2 and be within therange of a 32 bit signed integer.

# Output

For each case, print the case number and the largest integerp such that x is a perfect pth power.

# Output for Sample Input

3

17

1073741824

25

Case 1: 1

Case 2: 30

Case 3: 2

#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
int res=0;char c;
while((c=getchar())<'0' || c>'9');
while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
return res;
}
const int N=50100;
bitset<N> vis;
int prime[N>>3];
int cnt[N];
int ans[N>>3];
int p;
int gcd(int a,int b)
{
return b==0? a : gcd(b,a%b);
}
int main()
{
for(int i=2;i<N;i++)
{
if(!vis[i])
{
prime[p++]=i;
for(ll j = 1LL*i*i;j<N;j+=i) vis[j]=1;
}
}
int T=in(),ii=1;
ll n;
while(T--)
{
scanf("%lld",&n);
bool flag=0;
if(n<0)n=-n,flag=1;

mem(cnt,0);
bool ok=1;
int c=0;
for(int i=0;i<p && 1LL*prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==0)
{
ans[c++]=prime[i];
while(n%prime[i] == 0)
{
cnt[prime[i]]++;
n /= prime[i];
}
}
}
if(n>1)
{
printf("Case %d: %d\n",ii++,1);
continue;
}

int tmp = cnt[ans[0]];
for(int i=1;i<c;i++)
{
tmp = gcd(tmp,cnt[ans[i]]);
}
if(flag && tmp%2==0)
{
while(tmp%2==0) tmp>>=1;
printf("Case %d: %d\n",ii++,tmp);
continue;
}
printf("Case %d: %d\n",ii++,tmp);

}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：34679次
• 积分：1759
• 等级：
• 排名：千里之外
• 原创：148篇
• 转载：0篇
• 译文：0篇
• 评论：2条
阅读排行
最新评论