Euler's Function and Its Properties
For a positive integer n, the Euler's function is the number of the numbers in the number of <= n and the number of the numbers in the number of n.
For example, euler (8) = 4, because 1, 3, 5, 7 are both 8 and 8.
Expression of the Euler function: euler (x) = x (1-1/p1) (1-1/p2) (1-1/p3) (1-1/p4 )... (1-1/pn), where p1, p2 ...... All prime factors whose pn is x, and whose x is not an integer of 0. Euler (1) = 1 (the number of unique and 1 mutual quality is 1 itself ).
Extension of euler's formula: The sum of all quality factors of a number is euler (n) * n/2.
Special Properties: WHEN n is an odd number)
Euler's function is a product function-if m, n are mutually qualitative, Phi (mn) = PHI (m) PHI (n ).
If n is the k power of prime number p, Phi (n) = p ^ k-p ^ (k-1) = (PM) p ^ (k-1 ), except for the multiples of p, all other numbers are in the same quality as n.
Set a to a prime factor of N. If (N % a = 0 & (N/a) % a = 0), E (N) exists) = E (N/a) * a; If (N % a = 0 & (N/a) %! For example, E (N) = E (N/a) * (a-1 ).
Euler's theorem: for the positive integers a and n of the mass, there is a Phi (n) limit 1 mod n.
Code implementation:
The most efficient linear time screening method is used to evaluate the prime number and Euler's function.
The phi [MAXN] array stores the Euler's function, and prime [MAXN] stores the prime number table.
bool com[MAXN];int primes, prime[MAXN], phi[MAXN];phi[1] = 1;for (int i = 2; i <= n; ++i){ if (!com[i]) { prime[primes++] = i; phi[i] = i-1; } for (int j = 0; j < primes && i*prime[j] <= n; ++j) { com[i*prime[j]] = true; if (i % prime[j]) phi[i*prime[j]] = phi[i]*(prime[j]-1); else { phi[i*prime[j]] = phi[i]*prime[j]; break; } }}