Just do the bare question directly.
#include <cstdio>#include<cstdlib>#include<algorithm>using namespaceStd;typedefLong Longll;Const intp[]={2,3,5,7, One, -, -, +, at};intt;ll n,mx;ll gcd (ll a,ll b) {returnB?GCD (b,a%b): A;} LL Mul (ll a,ll b,ll p) {ll R=a*b-(LL) ((Long Double) a/p*b+1e-8)*p; returnr<0? r+P:r;} ll QP (ll a,ll b,ll p) {ll R=1; for(; b;b>>=1, A=mul (a,a,p))if(b&1) r=Mul (r,a,p); returnR;}BOOLchk (ll a,ll n,ll R,ll s) {ll x=QP (a,r,n), pre=x; for(intI=1; i<=s;i++,pre=x) {x=Mul (x,x,n); if(x==1&&pre!=1&&pre!=n-1)return 0; } returnx==1;}BOOLMr (LL N) {ll R=n-1, s=0; while(! (r&1)) r>>=1, s++; for(intI=0;i<9; i++) { if(p[i]==n)return 1; if(!chk (P[i],n,r,s))return 0; } return 1;} ll Po (ll n,ll a) { for(LL i=1, k=2, X=rand ()%n,y=x;; i++) {x= (Mul (x,x,n) +a)%N; if(GCD (N,abs (y-x)) ^1)returnGCD (N,abs (yx)); if(i==k) y=x,k<<=1; }}voidSol (ll N) {if(n==1)return; if(MR (N)) {Mx=max (mx,n);return;} ll T=N; while(t==n) T=po (N,rand ()%N); Sol (t), Sol (n/t);}intMain () {Srand (819733672); scanf ("%d",&u); while(t--) {scanf ("%lld", &n), mx=0, Sol (n); if(Mx==n) puts ("Prime");Elseprintf"%lld\n", MX); } return 0;}
Miller-rabin,pollard-rho (BZOJ3667)