Euler's Function & Chinese Remainder Theorem in algorithm Summary

Source: Internet
Author: User

Euler's Function & Chinese Remainder Theorem in algorithm Summary

1. Euler's Function

  Concept:In number theory, for a positive integer N, the Euler's function is the number of numbers that are less than or equal to the number of numbers that intersect with N.

  General Formula: Phi (x) = x (1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4 )..... (1-1/PN)

    P1, P2 ...... All prime factors whose PN is x. x is an integer not 0.

  Note:

1) PHI (1) = 1.

2) Each prime factor is only one. For example, 12 = 2*2*3, then PHI (12) = 12 * (1-1/2) * (1-1/3) = 4

(3) If n is the k power of prime p ), except for the multiples of P, all other numbers are in the same quality as N.

4) PHI (Mn) = PHI (m) PHI (N)

5) WHEN n is an odd number)

  Code implementation:

1) calculate the number of ouarla directly:

1/* Euler's function value whose return value is N */2 int Euler (int n) 3 {4 int S = N, I, m; 5 m = SQRT (N ); 6 For (I = 2; I <= m; I ++) {7 if (N % I = 0) 8 S = s/I * (I-1 ); 9 While (N % I = 0) 10 N/= I; 11} 12 if (n> 1) 13 s = s/n * (n-1); 14 return S; 15}

2) create tables

1/* print the Euler function table of 1-maxn */2 int A [maxn] = {, 0}; 3 void Euler () 4 {5 Int I, J; 6 For (I = 2; I <= maxn; I ++) 7 if (! A [I]) 8 for (j = I; j <= maxn; j + = I) 9 {10 if (a [J] = 0) A [J] = J; 11 A [J] = A [J]/I * (I-1); 12} 13}

2. China Residue Theorem

Original article:
The question in Sun Tzu's computing Sutra: I don't know the number of things. I have three questions: One, two, five, one, three, and seven, and two. What is the total number of things?
Solution in Sun Tzu's computing Sutra: three or three numbers, take the number of 70, multiply by the number of two; five numbers, take the number of 21, multiply by the remainder three-phase; seven numbers, take the number 15 and multiply it by the remainder. Add the product and subtract the multiple of one hundred and five.

Conclusion:

    Any fixed integer is M. When M/A is a, m/B is B, M/C is C, M/D is D ,..., When m/z is more than z, here a, B, c, d ,..., When Z is the divisor and the divisor is any natural number, the remainder a, B, c, d ,......, When Z is a natural integer.

1) when the proposition is correct, there is a solution within the least common multiples of the divisor, and there is a unique solution within each least common multiple.

2) When M is within the least common multiple of two or more divisor, the divisor and remainder of the two or more operators can locate the specific position of M within the least common multiple, that is, the size of M.

3) correct propositions: Divide them by a, B, c, d ,..., The number of different remainder combinations in Z = A, B, C, D ,..., Minimum Public multiples of Z = cycles of different remainder combinations.

  Specific steps (take Sun Tzu's computing Sutra as an example ):

1) identify three numbers: Find the minimum number 15 of 7 Division remainder 1 from the public multiples of 3 and 5, find the minimum number 21 after division of 5 and 1 from the public multiples of 3 and 7, and find the minimum number 70 after division of 3 and 1 from the public multiples of 5 and 7.

2) Multiply by 15 by 2 (2 is the remainder of the final result divided by 7) and multiply by 21 by 3 (3 is the remainder of the final result divided by 5). Likewise, multiply 70 by 2 (2 is the remainder of the final result divided by 3), and then add the three products (15*2 + 21*3 + 70*2) to get and 233.

3) divide by 233 by the minimum public multiple of 3, 5, and 7 by 105, and obtain the remainder 23, that is, 233% 105 = 23. The remainder 23 is the minimum number that meets the condition.

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.