For a positive integer n, the Euler function is the number of <= n coprime number of N.
For example Euler (8) = 4, because 1,3,5,7 are both and 8 coprime.
Euler function expression formula: Euler (x) =x (1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4) ... (1-1/PN), where P1,P2......PN is the all-factor of x, and X is an integer that is not 0. Euler (1) =1 (the number of unique and 1 coprime is 1 itself).
The extension of Euler's formula: the sum of all the mass factors of a number is Euler (n) *n/2.
Special properties: When n is odd, φ (2n) =φ (n)
Euler functions are integrable functions--if M,n coprime, φ (MN) =φ (m) φ (n).
If n is the K-power of the prime number p, φ (n) =p^k-p^ (k-1) = (p-1) p^ (k-1), because except for multiples of p, the other numbers are followed by n coprime.
Set a for the mass factor of N, if (n% A = = 0 && (n/a)% A = = 0) There is E (n) =e (n/a) * A; if (n% A = = 0 && (n/a)% A = 0) there is: E (n) = E (n/a) * (A-1).
Euler's theorem: for coprime positive integers a and N, there is aφ (n) ≡1 mod n.
Code implementation:
The most efficient linear time sieve method for calculating prime and Euler functions.
PHI[MAXN] Array holds the Euler function, PRIME[MAXN] is the prime number table.
BOOL Com[maxn];int primes, PRIME[MAXN], PHI[MAXN];p hi[1] = 1;for (int i = 2; I <= n; ++i) { if (!com[i]) { P rime[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;}}}
Euler's function and its properties