Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1335 Accepted Submission(s): 401
Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.
Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> using namespace std; #define mod 1000000007 __int64 vec[33]; int ans; __int64 prime[10500],pans; __int64 re; __int64 n; int init() { int i; memset(prime,0,sizeof(prime)); for(i=2;i<=10000;i++) { if(!prime[i]) for(int j=i+i;j<10050;j=j+i) { prime[j]=1; } } pans=0; for(i=2;i<=10000;i++) { if(!prime[i]) prime[pans++]=i; } return 1; } __int64 ff(__int64 k) { int i,j; __int64 m=(__int64)(n/k),a[5],b[]={2,3,5}; a[0]=m;a[3]=(1+m),a[1]=(1+2*m),a[2]=(3*m*m+3*m-1); for(j=0;j<=2;j++) { for(i=0;i<4;i++) { if(a[i]%b[j]==0) { a[i]/=b[j]; break; } } } return a[2]%mod*a[0]%mod*a[1]%mod*a[3]%mod*k%mod*k%mod*k%mod*k%mod; } void dfs(int now,int len,__int64 s ) { int i; if(len>=ans) return; if(now>=ans) return; if(len&1) { re+=ff(s); re%=mod; if(re<0) re+=mod; } else { re-=ff(s); re%=mod; if(re<0) re+=mod; } for(i=now+1;i<ans;i++) { dfs(i,len+1,s*vec[i]); } } bool isp(__int64 ii,__int64 pri) { if(pri==1) return false; __int64 m=sqrt((double)pri); for(__int64 i=ii+1;i<pans&&prime[i]<=m;i++) { if(pri%prime[i]==0) return false; } return true; } int main() { init(); int tcase,i; scanf("%d",&tcase); while(tcase--) { scanf("%I64d",&n); ans=0; __int64 m=(__int64)sqrt((double)n)+1; __int64 tempn=n; bool flag=true; if(isp(-1,n)) flag=false; else flag=true;__int64 ii=prime[0]; for(__int64 i1=0;flag&&ii<=tempn&&i1<pans;i1++) { ii=prime[i1]; if(tempn%ii==0) { vec[ans++]=ii; while(tempn%ii==0) { tempn/=ii; } if(isp(i1,tempn)) flag=false; } } if(!flag) vec[ans++]=tempn; re=ff(1); for(i=0;i<ans;i++) dfs(i,0,vec[i]); printf("%I64d\n",re); } return 0; }