您的位置:首页 > 其它

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

2016-02-27 13:22 363 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: