LightOJ - 1220

Time Limit: 500MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

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 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

Source

Problem Setter: Muhammad Rifayat Samee
Special Thanks: Jane Alam Jan
/**       
          题意: n = a ^p,p最大是多少
          做法:质因数分解,p = gcd(e1,e1.....en);如果n为负数,质因子不能为偶数;
**/
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define pi acos(-1)
#define maxn 1000100
using namespace std;
int tot = 0;
long long  phi[maxn/10];
bool num[maxn];
int a[1100];
int b[1100];
long long  n;
int res = 0;
int gcd(int a,int b)
{
    if(b == 0) return a;
    else return gcd(b,a%b);
}
void getprime()
{
    tot = 0;
    for(long long  i=2; i<maxn; i++)
    {
        if(!num[i])
        {
            phi[tot++] = i;
            for(long long j=i*i; j<=maxn; j+=i)
            {
                num[j] = true;
            }
        }
    }
}
void solve()
{
    res = 0;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0; phi[i]*phi[i] <= n; i++)
    {
        if(n%phi[i] == 0)
        {
            a[res] = n;
            while(n%phi[i] == 0)
            {
                b[res] ++;
                n /= phi[i];
            }
            res++;
        }
    }
    if(n != 1)
    {
        a[res] = n;
        b[res++] = 1;
    }
}
int main()
{

//   freopen("in.txt","r",stdin);
    int T;
    getprime();
    scanf("%d",&T);
    int Case = 1;
    while(T--)
    {
        bool flag = true;
        scanf("%lld",&n);
        if(n < 0) n = -n,flag = false;
        solve();
        int t = b[0];
        if(!flag)
        {
            if(t %2 == 0)
            {
                while(t %2 == 0)
                    t/=2;
            }
            for(int i=0; i<res; i++)
            {
                if(b[i] %2 == 0)
                {
                    while(b[i] % 2 == 0)
                    {
                        b[i] /=2;
                    }
                }
                t = gcd(t,b[i]);
            }
        }
        else
        {
            for(int i=0; i<res; i++)
            {
                t = gcd(t,b[i]);
            }
        }
        printf("Case %d: %d\n",Case++,t);
    }
    return 0;
}

 

posted on 2015-05-03 21:29  `Elaine  阅读(330)  评论(0编辑  收藏  举报

导航