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
| #include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN=100;
LL gcd(LL a,LL b){ if(!b)return a; return gcd(b,a%b); }
LL qpow(LL a,LL b,LL mod){ LL res=1,base=a%mod; for(;b;b>>=1,base=(__int128_t)base*base%mod)if(b&1){ res=(__int128_t)res*base%mod; } return res; }
LL MR(LL p){ if(p<2)return 0; if(p==2)return 1; if(p==3)return 1; LL d=p-1,r=0; while(!(d&1))d>>=1,++r; for(LL k=1;k<=10;++k){ LL a=rand()%(p-2)+2; LL x=qpow(a,d,p); if(x==1||x==p-1)continue; for(int i=1;i<=r-1;++i){ x=(__int128_t)x*x%p; if(x==p-1)break; } if(x!=p-1)return 0; } return 1; }
LL PR(LL x){ LL s=0,t=0; LL c=1ll*rand()%(x-1)+1; int step=0,goal=1; LL val=1; for(goal=1;;goal<<=1,s=t,val=1){ for(step=1;step<=goal;++step){ t=((__int128_t)t*t+c)%x; val=(__int128_t)val*abs(t-s)%x; if((step%127)==0){ LL d=gcd(val,x); if(d>1)return d; } } LL d=gcd(val,x); if(d>1)return d; } }
LL fac[MAXN],cnt[MAXN],tot,len,ufac[MAXN];
void divide(LL n){ if(n<2)return; if(MR(n)){ fac[++tot]=n; return; } LL d=n; while(d>=n)d=PR(n); divide(d); divide(n/d); }
void brk(int n){ memset(cnt,0,sizeof cnt); tot=0; divide(n); sort(fac+1,fac+tot+1); for(int i=1;i<=tot;++i){ if(fac[i]!=fac[i-1])ufac[++len]=fac[i]; ++cnt[len]; } }
int main(){ srand((unsigned)time(nullptr)); brk(100000000); for(int i=1;i<=len;++i){ cout<<ufac[i]<<' '<<cnt[i]<<'\n'; } return 0; }
|