(Solution:)
根据题意我们可以推出以下式子
(sumlimits_{p in prime};sumlimits_{i=1}^n;sumlimits_{j=1}^n ;[gcd(i,j)=p])
(ecause gcd(a*x,a*y)=p=gcd(x,y)=1)
( herefore)可得出下式
(sumlimits_{p in prime};sumlimits_{i=1}^{lfloorfrac{n}{p} floor};sumlimits_{j=1}^{lfloorfrac{n}{p} floor};[gcd(i,j)=1])
又(ecause)是有序数对,但是存在两数都是素数的情况
( herefore)可得出下式
(sumlimits_{p in prime};left(sumlimits_{i=1}^{lfloorfrac{n}{p} floor};left(2sumlimits_{j=1}^i[gcd(i,j)=1] ight)-1 ight))
(ecause gcd(i,j)=1)可以用欧拉函数求解
( herefore)可得出下式
(sumlimits_{p in prime}left(2sumlimits_{i=1}^{lfloorfrac{n}{p} floor}phi(i)-1 ight))
最后求完这些东西,再加上一个前缀和优化即可
(Code:)
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0' || c>'9'){if(c=='-') f=0;c=getchar();}
while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?x:-x;
}
const int N=1e7+10,M=1e6+10;
int n,cnt,p[M],phi[N],sum[N],ans;
bool vis[N];
void Euler_seive()
{
phi[1]=1;
for(int i=2;i<=n;i++)
{
if(!vis[i]){p[++cnt]=i;phi[i]=i-1;}
for(int j=1;j<=cnt && i*p[j]<=n;j++)
{
vis[i*p[j]]=1;
if(i%p[j]==0)
{
phi[i*p[j]]=phi[i]*p[j];
break;
}
else phi[i*p[j]]=phi[i]*phi[p[j]];
}
}
}
signed main()
{
n=read();
Euler_seive();
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+phi[i];
for(int i=1;i<=cnt;i++) ans+=2*sum[n/p[i]]-1;
printf("%lld",ans);
return 0;
}