推导,先看上三角形,坐标互素即为满足条件的点,顶点总数为欧拉函数的和
#include <iostream>
#include <stdio.h>
using namespace std;
int sum[1010];
int eu(int n)
{
int i,ret=1;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
n/=i;
ret*=i-1;
while(n%i==0)
{
ret*=i;
n/=i;
}
}
}
if(n>1) ret*=n-1;
return ret;
}
int main()
{
int cas,i,n;
sum[1]=1;
for(i=2;i<=1002;i++)
sum[i]=sum[i-1]+eu(i);
freopen("in.txt","r",stdin);
cin>>cas;
for(i=1;i<=cas;i++)
{
cin>>n;
cout<<i<<" "<<n<<" "<<2*sum[n]+1<<endl;
}
return 0;
}