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.
InputInput 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.
OutputFor each case, print the case number and the largest integer p such that x is a perfect pth power.
Sample Input3
17
1073741824
25
Sample OutputCase 1: 1
Case 2: 30
Case 3: 2
#include<cmath>
#define M 100000
#define ll long long
using namespace std;
struct Pw
{
ll x;
int p;
}num[M],w[2000];
int pos1 = 0,pos2 = 0;
void init()
{
ll max = pow(2,32);
int i,j;
for (i = 2;i <= 65536;i ++)
{
j = 2;
while (pow(i,j) <= max)
{
num[pos1].x = pow(i,j);
num[pos1].p = j;
++ pos1,++ j;
}
}
for (i = -2;i >= -1300;i --)
{
j = 3;
while (pow(i,j) >= -max)
{
w[pos2].x = pow(i,j);
w[pos2].p = j;
++ pos2,j += 2;
}
}
}
int main()
{
init();
int t,i,j;
scanf("%d",&t);
for (j = 0;j < t;j ++)
{
ll a;
scanf("%lld",&a);
int flag = 1;
if (a > 0)
{
for (i = 0;i < pos1;i ++)
if (a == num[i].x)
{
printf("Case %d: %d\n",j + 1,num[i].p);
break;
}
if (i == pos1)
printf("Case %d: %d\n",j + 1,1);
}
else
{
for (i = 0;i < pos2;i ++)
if (a == w[i].x)
{
printf("Case %d: %d\n",j + 1,w[i].p);
break;
}
if (i == pos2)
printf("Case %d: %d\n",j + 1,1);
}
}
return 0;
}
sample input:
82147483647
-2147483648
32
-32
64
-64
4
-4
Output:
Case 1: 1
Case 2: 31
Case 3: 5
Case 4: 5
Case 5: 6
Case 6: 3
Case 7: 2
Case 8: 1