//pku2478
//思路,dp,递推方式为dp[i] =dp[i-1]+phi[i];
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
int phi[maxn+10];
LL dp[maxn+10];
int main()
{
int n;
for(int i=1;i<=maxn;i++)phi[i]=i;
for(int i=2;i<=maxn;i+=2)phi[i]/=2;
for(int i=3;i<=maxn;i+=2)if(phi[i]==i)
for(int j=i;j<=maxn;j+=i)phi[j]=phi[j]/i*(i-1);
for(int i=2;i<=maxn;i++)dp[i]=dp[i-1]+phi[i];
while(cin>>n&&n)cout<<dp[n]<<endl;
}
poj2478 Farey Sequence
最新推荐文章于 2020-07-21 15:08:37 发布