Euler's function summary [number theory] [Euler's function]

Source: Internet
Author: User

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:

  1. The sum of all quality factors of a number isEuler (n) * n/2.
  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





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.