显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAXN 4000006
int phi[MAXN];
long long sum[MAXN];
int n;
void init()
{
for(int i=1;i<=MAXN;++i) phi[i]=i;
memset(sum,0,sizeof(sum));
for(int i=2;i<=MAXN;++i)
if(phi[i]==i)
for(int j=1;j*i<MAXN;++j)
phi[i*j]=phi[i*j]/i*(i-1);
for(int i=1;i<=MAXN;++i)
sum[i]=sum[i-1]+phi[i];
}
int main()
{ freopen("gcd_extreme.in","r",stdin);
freopen("gcd_extreme.out","w",stdout);
init();
while(scanf("%d",&n)&&n)
{ long long gh=0;
for(int i=1;i<=n;++i)
gh+=i*(sum[n/i]-1);
printf("%lld",gh);
}
}