题意见紫书P343.
既然要是b的p次方, 很容易就能想到唯一分解然后每个质因数的次数的gcd, 可是一直无脑wa真是快崩溃了。。瓦擦擦然后看了别人代码才知道原来还可以是负数。。。真是【哔---】了- -, 然后负数变成整数再分解再gcd, 这里就要注意次幂不能是偶数,所以while(!(ans & 1)) ans >>= 1;
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5+50 ;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;
vector<ll>pri;
int prime[maxn],cnt,num[maxn];
void init() {
cnt = 0;
OFF(prime);
for (ll i = 2; i <= 100000; i++) {
if (prime[i] >= 0) continue ;
for (ll j = i; j <= 100000; j += i)
prime[j] = cnt;
pri.push_back(i);
cnt++;
}
}
int main () {
#ifdef LOCAL
freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
#endif
ll n;
init();
// for (int i = 0; i <= 10; i++) cout << pri[i] << " " ;
// puts("");
while (scanf("%lld",&n) && n) {
int ans = 0;
int flag = 0;
if (n < 0) {
flag = 1;
n = -n;
}
for (int i = 0; pri[i] * pri[i] <= n && i < pri.size(); i++) {
ll v = pri[i];
if(n % v) continue ;
int t = 0;
while (n % v == 0) {
t++;
n /= v;
}
ans = __gcd(ans,t);
if (ans == 1) break;
}
if (n > 1 || ans == 0) ans = 1;
while (flag && !(ans & 1)) ans >>= 1;
printf("%d\n",ans);
}
return 0;
}