Code:
#include<bits/stdc++.h>
#define maxn 10000004
#define ll long long
#define M 1000002
using namespace std;
void setIO(string s)
{
string in=s+".in";
freopen(in.c_str(),"r",stdin);
}
int cnt;
bool vis[maxn];
int prime[maxn], phi[maxn];
ll sumv[maxn];
ll Sum(ll n) { return (n * (n + 1)) / 2; }
inline void Init()
{
int i,j;
phi[1]=1;
for(i=2;i<=M;++i)
{
if(!vis[i]) prime[++cnt]=i, phi[i]=i-1;
for(j=1;j<=cnt&&1ll*prime[j]*i<=M;++j)
{
vis[prime[j]*i]=1;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
for(i=1;i<=M;++i) sumv[i]=sumv[i-1]+1ll*phi[i];
}
map<int,ll>sumphi;
ll get(int n)
{
if(n<=M) return 1ll*sumv[n];
if(sumphi[n]) return sumphi[n];
ll re=1ll*Sum(n);
int i,j;
for(i=2;i<=n;i=j+1)
{
j=n/(n/i);
re -= 1ll*(j-i+1) * 1ll*get(n/i);
}
return re;
}
int main()
{
// setIO("input");
Init();
int n;
scanf("%d",&n);
printf("%lld\n",get(n));
return 0;
}