http://www.lydsy.com/JudgeOnline/problem.php?id=2190
At first did not think Qaq saw the solution, although the method and the solution is different.
Since the coordinates starting with 1 or ending are special, first do not consider.
Considering the coordinates starting at 2, it is not selected when this point is not at the first point of a ray that is emitted at a point. It means that it is not a multiple of the first point!
So I think that when the coordinates gcd (x, y)!=1, this point cannot be seen! Because D=GCD (x, y)!=1, there are obviously coordinates (X/D, y/d) on this line! (the slope can be used to engage in.) But this is obvious. )
And find it seems a little hard to calculate? For example, some points (4, 2) can be seen but gcd (4, 2) = 2, where is the problem? (2, 1) is not on the ray!
Minus 1 of all the coordinates ....
And then you'll find that it's all right ......... ......
And the answer is,
$$\sum_{x=1}^{n-1} \sum_{y=1}^{n-1} [gcd (x, y) =1]$$
This is a special case of Möbius ... Direct Euler functions can be on ....
It is
$$\sum_{1<=i<=n-1} \phi (i) $$
Then take a 2, because two times, so minus 1, and then the original coordinates of the two next to the first, so +2, so the answer is
$$1+2\sum_{1<=i<=n-1} \phi (i) $$
#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x)? puts ("Error"): 0) Inline const int Getint () {int r=0, k=1; char C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; } #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) const int N=40005;int p[n], CNT, np[n], phi[n];void init (int N) {Phi[1]=1;for1 (i, 2, n) {if (!np[i]) p[++cnt]=i, Phi[i]=i-1;for1 (J, 1, CNT) {int t=p[j]*i; if (t>n) break;np[t]=1;if (i%p[ j]==0) {phi[t]=phi[i]*p[j]; break;} PHI[T]=PHI[I]*PHI[P[J]];}} int main () {int n=getint (); init (n-1); int Ans=0;for2 (i, 1, N) ans+=phi[i];ans=ans*2+1;print (ans); return 0;}
Description
As a sports Commissioner, C June is responsible for the training of the honor guard. Guard of Honor is composed of students of N * N of the square, in order to ensure that the procession uniform, c June will follow the guard of Honor's left rear, according to the number of students in the line of sight to determine whether the team is neat (such as). Now, C-June wants you to tell him the number of students you can see when the team is neat.
Input
A total of a number n.
Output
A total of a number, that is, c June should see the number of students.
Sample Input 4
Sample Output 9
HINT
"Data size and conventions" for 100% of data, 1≤n≤40000
Source
Arithmetical
"Bzoj" 2190: [SDOI2008] Honor guard (Euler function)