Link: http://poj.org/problem? Id = 3090
In the coordinate system, select a point from the point 0 ≤ x, y ≤ n in the x and y ≤ n, and these points do not pass through other points.
Idea: Obviously, the intersection of (0, 0) and (x, y) does not pass through other points only when x and y have mutual quality. For X, when Y is equal to N, all the points that can be selected are less than or equal to N and the number of mutual quality with N. A total of Euler (n) points are not overlapped. So we can obtain the recursive formula AA [I] = AA [I] + 2 * Euler (n ).
Code:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <map>#include <cstdlib>#include <queue>#include <stack>#include <vector>#include <ctype.h>#include <algorithm>#include <string>#include <set>#define PI acos(-1.0)#define maxn 10005#define INF 0x7fffffff#define eps 1e-8typedef long long LL;typedef unsigned long long ULL;using namespace std;int aa[1005];int Euler(int tot){ int num=tot; for(int i=2; i<=tot; i++) { if(tot%i==0) num=num/i*(i-1); while(tot%i==0) tot/=i; } return num;}void init(){ aa[0]=0; aa[1]=3; for(int i=2; i<=1000; i++) aa[i]=aa[i-1]+Euler(i)*2;}int main(){ int T; scanf("%d",&T); init(); for(int ii=1; ii<=T; ii++) { int tot; scanf("%d",&tot); printf("%d %d %d\n",ii,tot,aa[tot]); } return 0;}