Euler's function is defined as follows: Euler (K) = (number of integers in [1, n-1] and N ).
Eg: Euler (8) = 4, because 1, 3, 5, 7 are both 8 and 8.
The following formula can be used:
Euler (K) = (p1-1) (p2-1 )...... (Pi-1) * (P1 ^ (a1-1) (P2 ^ (a2-1 ))...... (PI ^ (ai-1 ))
= K * (p1-1) (p2-1 )...... (Pi-1)/(P1 * P2 *...... Pi );
= K * (1-1/P1) * (1-1/P2)... (1-1/PK)
Therefore, the expression of the Euler function is as follows: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 ).
Based on the above nature, we can launch:
If (N % A = 0 & (n/a) % A = 0), E (n) = E (n/a) *;
If (N % A = 0 & (n/a) %! = 0) then there are: E (n) = E (n/a) * (A-1 );
Extension of Euler's formula:
- The sum of all quality factors of a number isEuler (n) * n/2.
- A prime numberNThe Euler's function is n-1.
The Program for finding the Euler function is given below:
// Directly solve the Euler's function and return Euler (n) int Euler (int n) {int res = N, A = N; For (INT I = 2; I * I <= A; I ++) {if (a % I = 0) {res = Res/I * (I-1 ); // division is performed first to prevent intermediate data overflow while (a % I = 0) A/= I; cout <res <"" <Endl ;}}if (A> 1) RES = Res/A * (A-1); Return res ;}
In the following table, a screening method is provided to create an Euler's function table:
// Euler's function table # define Max 1000001int Euler [Max]; void Init () {Euler [1] = 1; for (INT I = 2; I <Max; I ++) Euler [I] = I; for (INT I = 2; I <Max; I ++) if (Euler [I] = I) for (Int J = I; j <Max; j + = I) Euler [J] = Euler [J]/I * (I-1 );}
Answer one question first:
Poj3090 code