Title Description
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.
Enter a description
Input Description
A total of a number n.
Output description
Output Description
A total of a number, that is, c June should see the number of students.
Sample input
Sample Input
4
Sample output
Sample Output
9
Data range and Tips
Data Size & Hint
For 30% of data,1≤ n≤1000
For 100% of data,1≤ n≤40000
At the beginning of this topic on the Codevs sample output is wrong, let me think for a while, until the helper God help me to change the data.
We can take the bottom left corner as (0,0), and then the upper right corner of Nature (N-1, N-1), think about it will find that if a point (x, Y) can be observed, then (KX, KY) will not be observed , because from the lower left corner of the past, the two points in the same line.
It is also easy to prove that this picture is separated along the lower left-right side of the diagonal, the two parts are symmetrical, and a comparison needs to be noted that it does not belong to any part of it, but on the diagonal.
After we have deleted some of them, we get a triangle, according to the nature of the front label red, for the nth row, we only need to ask for the number of positive numbers less than or equal to N and n coprime, then we can use Euler function to solve.
Set the number of numbers that are less than or equal to N and N coprime to Phi (n), such as phi (8) = 4, because 1,3,5,7 and 8 coprime.
Phi (x) = x* (1-1/P1) * (1-1/P2) ... * (1-1/PN)
Where the P1 to PN are n factorization of x, it is important to note that each mass dependent number is computed only once, such as 12=2*2*3 phi (12) = 12* (1/2) * (2/3) = 4.
After finding Phi (2) to Phi (n-1) and multiplying by two, we need to deal specifically with the two points on the 0th and 0th lines and the point, that is, adding 3 (Rows 0th and 0th) can have Phi (0) set to 1 without special treatment.
The code is as follows (do not spit groove style)
1#include <iostream>2 using namespacestd;3 4 intAns, N, a[40001];5 6 intMain () {7CIN >>N;8n = n-1;9 for(inti =1; I <= N; i++)TenA[i] = i;//PHI (I) One for(inti =2; I <= N; i++)//Screening method for Phi (i) A if(A[i] = =i) { - intp =1; - while(p * I <=N) { theA[p * I] = a[p * I]/I * (i-1); -p++; - } - } + for(inti =1; I <= N; i++) -Ans + =A[i]; +Ans = ans *2+1;//( 0,1) is calculated two times, (1,0) is not computed. Acout <<ans; at return 0; -}
SDOI2008 Honor Guard