板子
1 #include <bits/stdc++.h> 2 #define LL long long 3 using namespace std; 4 LL n; vector <LL> z; 5 const LL mo=1e9+7; 6 LL gcd(LL x,LL y){ 7 return y?gcd(y,x%y):abs(x); 8 } 9 LL po(LL x,LL y){ 10 LL z=1; x%=mo; 11 for (;y;y>>=1,x=x*x%mo) 12 if (y&1) z=z*x%mo; 13 return z; 14 } 15 LL XX(LL x,LL y,LL z){ 16 /* 17 (long double)x/z*y求商可以有微小的误差,之后反正会+z%z模回来 18 但如果 没有x%=z,y%=z,商的误差可能会很大,这样作差时会±k*maxLL 而GG 19 */ 20 x%=z,y%=z; return ((x*y-(LL)((long double)x/z*y)*z)%z+z)%z; 21 // return (__int128)x*y%z; 22 } 23 int St(LL a,LL b){ //a^(b-1)!=1?&&二次探测 24 //二次探测定理:如果p是奇素数,则x^2≡1(mod p)的解为x=1||x=p-1(mod p); 25 if (a==b) return 0; 26 LL ans1=1,ans=1; 27 for (int i=64;i>=0;i--){ 28 ans=XX(ans1,ans1,b); 29 if (ans==1&&ans1!=1&&ans1!=b-1) return 1; 30 if ((b-1)&(1LL<<i)) ans=XX(ans,a,b); 31 ans1=ans; 32 } 33 return ans!=1; 34 } 35 int isP(LL x){ // x=1时为0; 36 return !(St(2,x)||St(3,x)||St(5,x)||St(7,x)||St(11,x)||St(13,x)||St(17,x)||St(19,x)||St(23,x)); 37 } 38 LL ra(LL x){ 39 return (rand()*2147483647LL+rand()*32767LL+rand())%x; 40 } 41 LL pro(LL x){ 42 LL x1=ra(x),x2=(XX(x1,x1,x)+1)%x,p=gcd(x1-x2,x); 43 while (p==1){ //不用判x=y,大不了返回x 44 x1=(XX(x1,x1,x)+1)%x; 45 x2=(XX(x2,x2,x)+1)%x; 46 x2=(XX(x2,x2,x)+1)%x; 47 p=gcd(x1-x2,x); 48 } 49 return p; 50 } 51 void divide(LL x){ 52 while (!(x&1)) z.push_back(2),x/=2; 53 if (x==1) return; 54 if (isP(x)) z.push_back(x);else{ 55 LL y=pro(x); 56 divide(x/y); divide(y); 57 } 58 } 59 int main(){ 60 scanf("%lld",&n); 61 divide(n); 62 printf("%lld=",n); 63 if (n==1){ 64 puts("1"); return 0; 65 } 66 sort(z.begin(),z.end()); 67 for (int q=0,h=0;q<z.size();q=h){ 68 while (h<z.size()&&z[h]==z[q]) ++h; 69 if (q!=h-1) printf("%lld^%d",z[q],h-q); else printf("%lld",z[q]); 70 if (h!=z.size()) printf("*"); 71 } 72 puts(""); 73 }