标签:int scanf cas \n lld pre names str div
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <queue> 7 #include <stack> 8 #include <cstdlib> 9 #include <iomanip> 10 #include <cmath> 11 #include <cassert> 12 #include <ctime> 13 #include <map> 14 #include <set> 15 using namespace std; 16 #pragma comment(linker, "/stck:1024000000,1024000000") 17 #define lowbit(x) (x&(-x)) 18 #define max(x,y) (x>=y?x:y) 19 #define min(x,y) (x<=y?x:y) 20 #define MAX 100000000000000000 21 #define MOD 1000000007 22 #define pi acos(-1.0) 23 #define ei exp(1) 24 #define PI 3.1415926535897932384626433832 25 #define ios() ios::sync_with_stdio(true) 26 #define INF 0x3f3f3f3f 27 #define mem(a) (memset(a,0,sizeof(a))) 28 typedef long long ll; 29 const int s=8; 30 char ch[26]; 31 ll mult_mod(ll a,ll b,ll c) 32 { 33 a%=c; 34 b%=c; 35 ll ret=0; 36 ll tmp=a; 37 while(b) 38 { 39 if(b&1){ 40 ret+=tmp; 41 if(ret>c) ret-=c; 42 } 43 tmp<<=1; 44 if(tmp>c) tmp-=c; 45 b>>=1; 46 } 47 return ret; 48 } 49 ll pow_mod(ll a,ll n,ll mod) 50 { 51 ll ans=1; 52 ll tmp=a%mod; 53 while(n) 54 { 55 if(n&1) ans=mult_mod(ans,tmp,mod); 56 tmp=mult_mod(tmp,tmp,mod); 57 n>>=1; 58 } 59 return ans; 60 } 61 bool check(ll a,ll n,ll x,ll t) 62 { 63 ll ret=pow_mod(a,x,n); 64 ll last=ret; 65 for(int i=1;i<=t;i++) 66 { 67 ret=mult_mod(ret,ret,n); 68 if(ret==1 && last!=1 && last!=n-1) return true; 69 last=ret; 70 } 71 if(ret!=1) return true; 72 else return false; 73 } 74 bool miller_pabin(ll n) 75 { 76 if(n<2) return false; 77 if(n==2) return true; 78 if((n&1)==0) return false; 79 ll x=n-1; 80 ll t=0; 81 while((x&1)==0) {x>>=1;t++;} 82 srand(time(NULL)); 83 for(int i=0;i<s;i++){ 84 ll a=rand()%(n-1)+1; 85 if(check(a,n,x,t)) return false; 86 } 87 return true; 88 } 89 ll factor[110]; 90 int tol=0; 91 ll gcd(ll a,ll b) 92 { 93 ll t; 94 while(b) 95 { 96 t=a; 97 a=b; 98 b=t%b; 99 } 100 if(a>=0) return a; 101 else return -a; 102 } 103 ll pollard_rho(ll x,ll c) 104 { 105 ll i=1,k=2; 106 srand(time(NULL)); 107 ll x0=rand()%(x-1)+1; 108 ll y=x0; 109 while(1) 110 { 111 i++; 112 x0=(mult_mod(x0,x0,x)+c)%x; 113 ll d=gcd(y-x0,x); 114 if(d!=1 && d!=x) return d; 115 if(y==x0) return x; 116 if(i==k){y=x0;k+=k;} 117 } 118 } 119 void findfac(ll n,ll k) 120 { 121 if(n==1) return ; 122 if(miller_pabin(n)) 123 { 124 factor[tol++]=n; 125 return ; 126 } 127 ll p=n; 128 ll c=k; 129 while(p>=n) p=pollard_rho(p,c--); 130 findfac(p,k); 131 findfac(n/p,k); 132 } 133 int main() 134 { 135 ll n; 136 scanf("%lld",&n); 137 if(miller_pabin(n)) printf("2\n"); 138 else 139 { 140 findfac(n,107); 141 ll ans=1; 142 for(int i=0;i<tol;i++) 143 { 144 145 ll pos=0; 146 while(n>0 && (n%factor[i]==0)) 147 { 148 pos++; 149 n/=factor[i]; 150 } 151 if(pos) ans*=(pos+1); 152 } 153 printf("%lld\n",ans); 154 } 155 return 0; 156 }
标签:int scanf cas \n lld pre names str div
原文地址:https://www.cnblogs.com/tingtin/p/9309298.html