分解质因数,求每个数指数,指数的gcd即是最大的p
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 1e7 + 100;
const int MAX_M = 1e6;
bool isp[MAX_N];
int primes[MAX_M];
void init() {
for (int i =2 ;i < MAX_N;i++) {
if (!isp[i]) {
primes[++primes[0]] = i;
for (int j = i + i;j < MAX_N;j+= i) {
isp[j] = true;
}
}
}
}
LL sum(LL N) {
bool neg = false;
if (N < 0) N = - N,neg = -1;
LL ans = 0;
for (int i = 1;i <= primes[0] && N != 1 && N >= primes[i];i++) {
LL loc = 0;
while (N % primes[i] == 0 && N != 1) {
N /= primes[i];
loc++;
}
ans = __gcd(ans,loc);
}
if (N > 1) ans = 1;
if (neg) {
while (ans % 2 == 0)
ans /= 2;
}
return ans;
}
int main() {
init();
int T;
sci(T);
for (int cs = 1;cs <= T;cs++) {
LL N;
scl(N);
printf("Case %d: %lld\n",cs,sum(N));
}
return 0;
}