Code:
#include<cstdio>
using namespace std;
const int maxn=4000005;
const int R=4000002;
const int N=4000002;
long long sumv[maxn],f[maxn];
int phi[maxn],prime[maxn],vis[maxn];
void solve(){
phi[1]=1;
int cnt=0;
for(int i=2;i<=R;++i){
if(!vis[i])prime[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&prime[j]*i<=R;++j){
vis[prime[j]*i]=1;
if(i%prime[j]!=0)phi[i*prime[j]]=phi[i]*(prime[j]-1);
else{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
}
}
for(int i=1;i<N;++i)
for(int j=i*2;j<N;j+=i)
f[j]+=i*phi[j/i];
for(int i=1;i<N;++i)
sumv[i]=sumv[i-1]+f[i];
}
int main(){
solve();
while(1){
int n;scanf("%d",&n);
if(!n)break;
printf("%lld
",sumv[n]);
}
return 0;
}