Euler's Function and Its Properties

Source: Internet
Author: User

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; }  }}





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.