POJ 3090 Visible Lattice Points Euler's Function
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, only when x and y are in mutual quality will the intersection of (0, 0) and (x, y) not pass through other points. For x, when y is equal to N, you can select a number of points less than or equal to N that are in 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include #include
#include
#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,ii,tot,aa[tot]); } return 0;}