Because the image is symmetrical about the diagonal. So we just look at the Triangle area.
Consider the x-axis as the denominator, the point of the circle as a molecule
{1/2},{1/3,1/2},{1/4,3/4},{1/5,2/5,3/5,4/5}, in turn
Written in the prefix and the form is {1/3,2/3},{},{a,A,1/3,2/3,1/4,3/4},{,1/ 3,2/3,1/4,3/4,1/5,2/5,3/5,4/5}
Found. This is a series of Valeo, that is, the number added by K is phi[k].
The final answer *2+ (0,1) + (1,0), (three) the point is good
#include <iostream> #include <cstdio> #include <cmath>using namespace std; #define N 1009int Phi[n];int Farey[n]={0,0,1};void init () { int i, J; for (i = 1; i < N; i++) phi[i] = i; for (i = 2; i < N, i++) if (i = = Phi[i]) for (j = i; J < N; J + = i) phi[j] = (Phi[j]/i) * (i-1);} int main () { init (); for (int i=3;i<n;i++) { farey[i]=farey[i-1]+phi[i]; } int cas,n,ca=1; scanf ("%d", &cas); while (cas--) { scanf ("%d", &n); printf ("%d%d%d\n", ca++,n,farey[n]*2+3); } return 0;}
If This rule is not found, it is also possible to recursively make a table, like a matrix and storage, using GCD to infer whether the current point is blocked by the previous point.
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib >using namespace Std;int mp[1005][1005];bool vis[1005][1005];int gcd (int a,int b) {return a%b==0?b:gcd (b,a%b);} int A[1005][1005];int Main () {memset (vis,0,sizeof (VIS)); int ans=0; for (int i=1;i<=1000;i++) {for (int j=1;j<=1000;j++) {int gg=gcd (I,J); if (Vis[i/gg][j/gg]) {a[i][j]+=a[i-1][j]+a[i][j-1]; A[I][J]-=A[I-1][J-1]; Continue } else {vis[i][j]=1; a[i][j]+=a[i-1][j]+a[i][j-1]+1; A[I][J]-=A[I-1][J-1]; }}} int n; int ca=1; int CAs; scanf ("%d", &cas); while (cas--) {scanf ("%d", &n); printf ("%d%d%d\n", ca++,n,a[n][n]+2); } return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
POJ 3090 Visible Lattice Points legal Lee Series | | By the meter