标签:mes ima name style set std 分享 ever iss
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1036 Accepted Submission(s): 373
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<map> 5 #include<set> 6 #include<vector> 7 #include<algorithm> 8 #include<cmath> 9 using namespace std; 10 #define LL long long 11 #define PI acos(-1.0) 12 LL thr[66]={1}; 13 int gcd(int a,int b){ 14 return b==0?a:gcd(b,a%b); 15 } 16 int main() 17 { 18 LL n,i,j; 19 for(i=1;i<=40;++i) thr[i]=thr[i-1]*3; 20 while(cin>>n){ 21 if(n==-1)break; 22 if(n==0){ 23 puts("0"); 24 continue; 25 } 26 LL ans=0; 27 for(i=1;i<=n;++i){ 28 ans+=thr[gcd(i,n)]; 29 } 30 if(n%2==0){ 31 ans=ans+thr[n/2]*(n/2); 32 ans=ans+thr[n/2+1]*(n/2); 33 } 34 else{ 35 ans=ans+thr[n/2+1]*n; 36 } 37 ans=ans/2; 38 ans=ans/n; 39 cout<<ans<<endl; 40 } 41 return 0; 42 }
标签:mes ima name style set std 分享 ever iss
原文地址:https://www.cnblogs.com/zzqc/p/9456682.html