Euler's function and its properties

Source: Internet
Author: User

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

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.