简化题意可知,实际上题目求得是gcd(i,j)=1(i,j<=n)的数对数目。
线性筛出n大小的欧拉表,求和*2+1即可。需要特判1.
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int N=;
//Code begin... int phi[N], prime[N], tot;
bool check[N]; void getEuler(int n){
mem(check,); phi[]=; tot=;
FOR(i,,n) {
if (!check[i]) prime[tot++]=i, phi[i]=i-;
FO(j,,tot) {
if (i*prime[j]>n) break;
check[i*prime[j]]=true;
if (i%prime[j]==) {phi[i*prime[j]]=phi[i]*prime[j]; break;}
else phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
int main ()
{
LL ans=;
int n;
scanf("%d",&n);
if (n==) {puts(""); return ;}
--n; getEuler(n);
FOR(i,,n) ans+=phi[i];
ans=ans*+;
printf("%lld\n",ans);
return ;
}