Mysterious Bacteria (unique decomposition ++ Euler prime number sieve)

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 are integers). More generally, x is a perfect pth power. Given the lifetime x of a mother RC-01 you are 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 will have magnitude at least 2 and be within the range of a 32 bit signed integer.

Output

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

Sample Input

3

17

1073741824

25

Sample Output

Case 1: 1

Case 2: 30

Case 3: 2

 Topic meaning:

Given a number x = b^p, find the maximum value of p

 

x = p1^x1*p2^x2*p3^x3*...*ps^xs

At first I thought I was looking for the maximum value in x1, x2, ... , xs, but later I found that I was wrong, x = b^p, x is only composed of a factor of the p-th power

If x = 12 = 2^2*3^1, let x = b^p, and 12 should be 12 = 12^1

So p = gcd(x1, x2, x3, ... , xs);

For example: 24 = 2^3*3^1, p should be gcd(3, 1) = 1, ie 24 = 24^1

         324 = 3^4*2^2, p should be gcd(4, 2) = 2, ie 324 = 18^2

 

There is a pit in this question, that is, x may be a negative number. If x is a negative number, x = b^q, q must be an odd number, so if the solution obtained by converting x to a positive number is an even number, it must be converted by dividing it by 2. odd number


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
bool IsPrime[1000010];    
int Prim[1000010],num = 0;    
void  init(){    
    int  j;    
    for(int i = 2; i <= maxn; i ++){    
        if(!IsPrime[i])    
            Prime[num++] = i;    
        for(j  = 0; j < num; j ++){    
            if(i * Prim[j] > maxn)    
                break;    
            IsPrime[i * Prim[j]] = true;    
            if(i % Prim[j] == 0)    
                break;    
        }    
    }//printf("%d\n",num);    
}
int gcd(int a,int b){
	return !b?a:gcd(b,a%b);
}
intmain()
{
	init();
	int t,ncase = 1;
	scanf("%d",&t);
	while(t--){
		bool falg = false;
		ll n;
		scanf("%lld",&n);
		if(n<0) {
			falg = true;
			n = -n;
		}
		int years = 0;
		for(int i = 0;i<num && Prim[i]<=n ; i++){
			//if(n == 1) break;
			int s = 0;
			if(n%Prim[i] == 0){
				while(!(n%Prim[i])){
					s++; n /= Prim[i];
				}
				if(!years) years = s;
				else ans = gcd(ans,s);
			}
			
		}
		if(n!=1) ans = 1;
		if(falg){
			while(!(ans&1)){
				years >>= 1;
			}
		}
		printf("Case %d: %d\n",ncase++,ans);
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325946800&siteId=291194637