UVA 10820(p322)----Send a Table

来源:互联网 发布:凯立德导航端口查询 编辑:程序博客网 时间:2024/06/07 01:51
#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int N=50000;int phi[N+50],x;long long ans;void init(){    memset(phi,0,sizeof(phi));  phi[1]=1;    for(int i=2; i<=N; i++)  if(!phi[i])        for(int j=i; j<=N; j+=i)        {            if(!phi[j]) phi[j]=j;            phi[j]=phi[j]/i*(i-1);        }}int main(){    init();    while(scanf("%d",&x)==1&&x)    {        //cout<<x<<endl;        if(x==1)printf("1\n");        else        {            ans=1;            for(int i=2;i<=x;i++)            {              // cout<<i<<endl;               ans+=2*phi[i];              // cout<<phi[x]<<endl;            }            printf("%lld\n",ans);        }    }    return 0;}

0 0