https://ac.nowcoder.com/acm/contest/3007/E
放下题解
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 32640; 5 ll vis[maxn*100],prime[maxn],prime_3[maxn]; 6 ll tot = 0; 7 void getPrime(){ 8 memset(vis,0,sizeof(vis)); 9 for(ll i=2;i<=maxn;i++){ 10 if(!vis[i])prime[tot++]=i,prime_3[tot-1] = i*i*i; 11 for(ll j=0;j<tot;j++){ 12 if(prime[j]*i>maxn)break; 13 vis[prime[j]*i]=1; 14 if(i%prime[j]==0)break; 15 } 16 } 17 } 18 19 int main(){ 20 getPrime(); 21 int t;scanf("%d",&t); 22 while(t--){ 23 ll n; 24 ll ans = 1; 25 scanf("%lld",&n); 26 for(int i = 0;i<tot&&prime[i]<=n;i++){ 27 while(n%prime_3[i] == 0){ 28 ans *=prime[i]; 29 n/=prime_3[i]; 30 } 31 while(n%prime[i] == 0){ 32 n/=prime[i]; 33 } 34 } 35 int L = 1, R = 1000000; 36 while(L<=R){//二分试除 37 int mid = (L+R)/2; 38 if((ll)mid*mid*mid<n) L = mid + 1; 39 else R = mid - 1; 40 } 41 if((ll)L*L*L == n) ans*=L; 42 printf("%lld ",ans); 43 } 44 return 0; 45 }