Title Effect: There is a grid component diagram, assuming that three people in a straight line, then the first person will not see a third person. Now, there is a man standing in the. I asked him if he could see the matrix of the number of n*n.
Think: If you want to stand (in the first place) This man sees a position (x, y) of a person. GCD (x, y) = = 1, which is a classic model, only requires a PHI within N and is able to.
The method is linear sieve.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 40010using namespace Std;int n;bool not_prime[max];int prime[max],primes;int phi[max];void Eratosthenes (); int main () { Cin >> n;n--; Eratosthenes (); int ans = 0;for (int i = 2;i <= n; ++i) ans + = Phi[i];cout << (ans << 1) + 3 << Endl;ret Urn 0;} void Eratosthenes () {phi[1] = 1;for (int i = 2;i <= n; ++i) {if (!not_prime[i]) prime[++primes] = I,phi[i] = i-1;for (int j = 1;j <= primes && prime[j] * i <= N; ++J) {not_prime[prime[j] * i] = true;if (i% prime[j] = = 0) {Phi[i * prime[j]] = phi[i] * prime[j];break;} Elsephi[i * Prime[j]] = phi[i] * (Prime[j]-1);}}}
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Bzoj 2190 sdoi 2008 Honor guard linear Euler sieve