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
#include<stack> #include<queue> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<map> #include<iostream> #include<string.h> #include<algorithm> #define maxn 1000005 #define maxm 10000005 #define MAXN 100005 #define MAXM 10005 #define mem(a,b) memset(a,b,sizeof(a)) #define ll long long #define inf 0x3f3f3f3f using namespace std; bool vis[maxm+5]; ll tot; ll p[maxn]; void get_prime(){ tot=0; mem(vis,true); for(ll i=2;i<=maxm;i++){ if(vis[i]){ p[tot++]=i; for(ll j=i*i;j<=maxm;j+=i)vis[j]=false; } } } int main(){ get_prime(); int t,test=0; scanf("%d",&t); while(t--){ ll n;scanf("%lld",&n); ll m=n; n=abs(n); ll x=0,ans=-1; while(p[x]<=n&&x<tot){ ll y=0; while(n%p[x]==0){y++;n/=p[x];} x++; if(ans==-1)ans=y; else ans=__gcd(ans,y); } if(n>1)ans=__gcd(ans,(ll)1); if(m<0){ while(ans%2==0)ans/=2; } else if(m==1||m==0) ans=1; printf("Case %d: %lld ",++test,ans); } }