Meaning of the questions: given a rectangular N * N points, find and looked to see how many points at the origin
Ideas: In addition to (1,0), (0,1), (1,1) xy among other points are coprime. So Euler function. fhi [i] is added to the 2 n, and then twice, plus 3.
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<map> #include<queue> #include<cmath> using namespace std; const int max_n=100010; int v[max_n],prime[max_n],phi[max_n]; void euler(int n) { memset(v,0,sizeof(v)); int m=0; for(int i=2;i<=n;i++) { if(v[i]==0) { v[i]=i; prime[++m]=i; phi[i]=i-1; } for(int j=1;j<=m;j++) { if(prime[j]>v[i]||prime[j]>n/i) break; v[i*prime[j]]=prime[j]; phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-1:prime[j]); } } } int main() { int n; euler(100000); int t; scanf("%d",&t); int x=0; while(t--){ scanf("%d",&n); long long sum=0; for(int i=2;i<=n;i++) sum+=phi[i]; sum=sum*2+3; printf("%d ",++x); printf("%d ",n); printf("%lld\n",n==0?0ll:sum); } }