您的位置:首页 > 其它

Send a Table 欧拉函数UVA - 10820

2017-06-28 09:42 344 查看
题意:给你个n,问有多少个pair < x,y > ,满足x,y互质。

分析,当x < y的时候,值f(y),就是将1到n的欧拉函数加起来,

当x>y,情况一样,就是倒过来。

只用x=1,y=1,的时候,x==y;

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;
const int maxn = 5e4+5;
long long phi[maxn];
void phi_table()
{
int n=50001;
for(int i=2;i<=n;i++) phi[i]=0;
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()
{
int n;
phi_table();
while(scanf("%d",&n)!=EOF&&n)
{
long long ans=0;
for(int i=2;i<=n;i++)
ans+=phi[i];
ans=ans*2+1;
printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: