Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:不知道为啥用欧拉函数。斜率判重土方法胡搞过了。In Reply To:不知道为啥用欧拉函数。斜率判重土方法胡搞过了。 Posted by:Liuzhaoliang at 2014-08-17 13:14:25 #include<cstdio> #include<iostream> #include<cstring> using namespace std; int phi[1110],prime[1110],pr,n; bool v[1110]; void getprime() { int i,j,k; memset(v, true,sizeof(v)); memset(phi,0,sizeof(phi)); pr=0; for(i=2;i<=n;i++) { if(v[i]==true) { prime[++pr]=i; phi[i]=i-1; } for(j=1;(j<=pr)&&(i*prime[j]<=n);j++) { v[i*prime[j]]=false; if(i%prime[j]==0) { phi[i*prime[j]]=phi[i] * prime[j]; break; } else phi[i*prime[j]]=phi[i] * (prime[j]-1); } } } int main() { int t,i,j,ans=0; scanf("%d",&t); for(j=1;j<=t;j++) { ans=0; scanf("%d",&n); getprime(); for(i=2;i<=n;i++) { ans+=phi[i]; } ans=ans*2+3; printf("%d %d %d\n",j,n,ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator