uva 10820

时间:2023-03-09 03:18:37
uva 10820
                                                                           /* 交表 _________________________________________________________________________________

                                                                               #include <iostream>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define fir first
#define sec second
#define pb(x) push_back(x)
#define mem(A, X) memset(A, X, sizeof A)
#define REP(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define rep(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<long,long> pll; LL T,n;
const int mod=1e9+7;
const int maxn=1e5+10; const int size=50000;//1-10000的表
int phi[size+1];
void phi_table() // 1 到 n 的欧拉phi函数值表 ( O( nlg(lgn) ) )
{
for(int i=2;i<=size;i++)
{
phi[i]=0;
}
phi[1]=1;
for(int i=2;i<=size;i++)
{
if(!phi[i])
{
for(int j=i;j<=size;j+=i)
{
if(!phi[j]) phi[j]=j;
phi[j] = phi[j]/i*(i-1);
}
}
}
} int main()
{
freopen("in.txt","r",stdin);
phi_table();
while(cin>>n&&n)
//while(cin>>T)
{
//REP(kase,1,T) { }
LL ans=1;
REP(i,2,n)
ans+=2*phi[i];
cout<<ans<<endl; }
return 0;
} /*
note :
debug :
optimize:
*/