标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1091 Accepted Submission(s): 350
1 #include <cstring> 2 #include <iostream> 3 #include <cstdio> 4 #include <algorithm> 5 #include <map> 6 using namespace std; 7 typedef long long LL; 8 map<int,int> m; 9 map<int,int>::iterator ite; 10 LL n,ans; 11 LL mod_pow(LL x,LL n,int mod) 12 { 13 LL res=1; 14 while(n) 15 { 16 if(n&1) 17 res=res*x%mod; 18 x=x*x%mod; 19 n>>=1; 20 } 21 return res; 22 } 23 int cal(LL n) 24 { 25 int i,j; 26 if(m[n]!=0) 27 return m[n]; 28 m[n]=mod_pow(2,n,2008)-2; 29 for(i=2;i*i<=n;i++) 30 { 31 if(n%i==0) 32 { 33 m[n]=(m[n]-cal(i)+2008)%2008; 34 if(i*i!=n) 35 m[n]=(m[n]-cal(n/i)+2008)%2008; 36 37 } 38 } 39 return m[n]; 40 } 41 int main() 42 { 43 m[0]=0; 44 m[1]=2; 45 m[2]=2; 46 //freopen("in.txt","r",stdin); 47 while(scanf("%d",&n)!=EOF) 48 { 49 if(n<=2) 50 printf("%d\n",m[n]); 51 else 52 { 53 m[n]=cal(n); 54 printf("%d\n",m[n]); 55 } 56 } 57 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5462132.html