1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef __int128 I;
namespace amazing{ inline ll gcd(ll a,ll b){ int shift=__builtin_ctzll(a|b); b>>=__builtin_ctzll(b); while(a){ a>>=__builtin_ctzll(a); if(a<b) swap(a,b); a-=b; }return b<<shift; } inline ll mul(ll x,ll y,ll p){ ll z=(long double)x/p*y; ll res=x*y-z*p; return res<p?res+p:res>p?res-p:res; } }
ll qpow(ll a,ll b,ll c){ ll r=1; while(b){ if(b&1) r=I(r)*a%c; a=I(a)*a%c; b>>=1; }return r; } bool miller_rabin(ll n){ if(n<=1) return false; ll t=n-1,k=0; while((t&1)==0) t>>=1,k++; for(int i=1;i<=10;i++){ ll a=qpow(rand()%(n-1)+1,t,n); for(ll j=1;j<=k;j++){ ll nex=I(a)*a%n; if(nex==1&&a!=1&&a!=n-1) return false; a=nex; } if(a!=1)return false; } return true; } ll pollard_rho(ll n){ while(true){ ll c=rand()%(n-1)+1; ll x=0,y=0,val=1; for(ll i=0;;i++){ x=amazing::mul(x,x,n)+c; if(x>n)x-=n;
if(x==y) break; val=amazing::mul(val,abs(x-y),n);
if((i&-i)==i||i%127==0){ ll d=__gcd(val,n); if(d==n) break; if(d>1) return d; } if((i&-i)==i) y=x; } } }
vector<ll> findfac(ll n){ vector<ll>res,stk(1,n); if(stk.back()==1) return res; while(!stk.empty()){ ll top=stk.back();stk.pop_back(); if(miller_rabin(top)) res.push_back(top); else{ ll fac=pollard_rho(top); stk.push_back(fac); stk.push_back(top/fac); } } return res; }
ll read(){ll x;scanf("%lld",&x);return x;}
int main(){ srand(time(NULL)); for(int T=read();T>=1;T--){ vector<ll>v=findfac(read()); sort(v.begin(),v.end()); if(v.size()==1) printf("Prime\n"); else printf("%lld\n",v.back()); } }
|