Light_oj 1220 Prime factorization j-mysterious bacteria
Time Limit:500MS
Memory Limit:32768KB
64bit IO Format:%LLD &%llusubmit Status Practice Lightoj 1220
Description
Dr. Mob has just discovered a deathly bacteria. He named it RC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly x days. Now RC-01 produces exactly p new deadly bacteria where x = BP (where B, p is integers). More generally, x is a perfect pth power. Given the lifetime x of a mother RC-01 you is to determine the maximum 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 would have magnitude at least 2 and being within the range of a + bit signed integer.
Output
For each case, print the case number and the largest integer p such that x is a perfect pth POW Er.
Sample Input
3
17
1073741824
25
Sample Output
Case 1:1
Case 2:30
Case 3:2
Test instructions: Given x, find the maximum p to make x=b^p;
Idea: Prime factorization. x= (P1^K1) * (P2^K2) *...* (PN^KN) = (P1^a1*p2^a2*...*pn^an) ^p=b^p, which is presented with a maximum of P,P=GCD (K1,k2,..., kn).
Note: Prime number decomposition is due to the number of primes only to 10^7, so the last factor needs to be a special award.
Pit point: X is negative when p can not be even, at this time as long as the previous proposed to all 2 to take in, the remaining left in the odd p is the answer.
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<vector>#include<stack>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<cctype>using namespaceStd;typedefLong Longll;Const intmaxn=10001000;Const intInf= (1<< in);Const Doubleeps=0.0000000001;Const DoublePi=acos (-1.0); ll X,p;BOOLIsprime[maxn];vector<ll>Prime;voidPlay_prime () {memset (IsPrime,1,sizeof(IsPrime)); isprime[1]=0; for(intI=2; i<maxn;i++){ if(!isprime[i])Continue; for(intj=i+i;j<maxn;j+=i) {Isprime[j]=0; } } for(intI=1; i<maxn;i++){ if(Isprime[i]) prime.push_back (i); }}intMain () {intT;cin>>T; Play_prime (); inttag=1; while(t--) {cin>>x; BOOLf=0; if(x<0) f=1, x=-x; P=-1; BOOLflag=1; for(intI=0;i< (int) prime.size () &&prime[i]*prime[i]<=x;i++){ if(X%prime[i])Continue; ll K=0; while(x%prime[i]==0) {x/=Prime[i]; K++; } if(p==-1) p=K; Elsep=__GCD (p,k); } if(x!=1) p=1; if(f) { while(p%2==0) p/=2; } cout<<" Case"<<tag++<<": "<<p<<Endl; } return 0;}
View Code
Light_oj 1220 Prime factorization