题解:输入n,有多少个二元组(x,y)满足:1<=x,y<=n,且x,y互素。
欧拉phi函数模板题。
ans=2*f(n)+1,其中f(n)=phi(2)+phi(3)+…phi(n)。
附上AC代码
#include <bits/stdc++.h>
#define FOPI freopen("INPUT.TXT", "r", stdin)
#define DOPI freopen("OUTPUT.TXT", "w", stdout)
using namespace std;
typedef long long int ll;
const int ind=0x3f3f3f3f,N=5e4+10;
const ll inlld=0x3f3f3f3f3f3f3f3f,mod=998244353;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
typedef pair<int,int> p;
int phi[N];
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n&&n){
memset(phi,0,sizeof(phi));
phi[1]=1;
for(int i=2;i<=n;i++){
if(!phi[i]){
for(int j=i;j<=n;j+=i){
if(!phi[j])phi[j]=j;
phi[j]=phi[j]/i*(i-1);
}
}
}ll ans=0;
ans+=phi[1];
for(int i=2;i<=n;i++)ans+=2*phi[i];cout<<ans<<endl;
}
return 0;
}