http://poj.org/problem?id=3090
Visible Lattice Points
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 6153 |
|
Accepted: 3662 |
Description
A Lattice Point (x, y) in the first quadrant (x and y is integers greater than or equ Al to 0), other than the origin, was visible from the origin if the line from (0, 0) to (x, y) does not Pass through any and lattice point. For example, the "point" (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (x, y) with 0≤ x, y -≤5 with lines from the Origin to the visible points.
Write a program which, given a value for the size, N, computes the number of visible points (x, yx, y ≤ N.
Input
The first line of input contains a single integer C (1≤ C ≤1000) which is the number of datasets T Hat follow.
Each dataset consists of a single line of input containing a single integer n (1≤ n ≤1000), which is the size.
Output
For each dataset, there are to being one line of output consisting of:the dataset number starting at 1, a single space, the S Ize, a single space and the number of the visible points for the size.
Sample Input
4245231
Sample Output
1 2 52 4 133 5 214 231 32549
Hiding a very deep Euler function problem, observe the following diagram, the graph into the upper and lower two triangles, observe the lower triangle, the horizontal axis starting from 2, the discovery can see the point there (2,1), (3,1), (3,2), (4,1), (4,3), (5,1), (5,2), (5,3), (5,4)
from which you can send a rule can see the point of the vertical and horizontal axis of the relationship is coprime, thus can find the lower triangle horizontal coprime number and ans, the triangle and the lower triangular same, we discussed the horizontal axis from 2, we ignore the three points
(0,1), (1,0), (a) Finally add, the final total number of ans = ans * 2 + 3;
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<algorithm>using namespacestd;intSolveintN) { intAns =N; for(inti =2; I * I <= N; i++) { if(n% i = =0) {ans= Ans-ans/i; while(n% i = =0) n/=i; } } if(N >1) ans= Ans-ans/N; returnans;}intMain () {intT, I, n, x =0; scanf ("%d", &t); while(t--) {x++; intAns =0; scanf ("%d", &N); intA =N; for(i =2; I <= N; i++) ans+=solve (i); Ans= ans *2+3; printf ("%d%d%d\n", X, A, ans); } return 0;}
POJ 3060 Visible Lattice Points