China Remainder Theorem

Source: Internet
Author: User
Introduction of Chinese Residue Theorem

Find a number so that the number is divided into \ (3 \) remainder \ (2 \), \ (5 \) remainder \ (3 \), and \ (7 \) yu \ (2 \).

Problem Solving

Next we will solve this problem according to the algorithm process of China's residual theorem and gradually explain its principle.

To solve this problem, we have a simple method: first finding the solution of each equation, and then adding its modulus to make it equal to the value of the solution of other equations.
However, this idea is difficult to solve. We introduce the following two properties:

Nature 1: \ (A + B) \ bmod P = A \ bmod P + B \ bmod p \)
Nature 2: \ (A * B) \ bmod P = (A \ bmod p) * B \)

Property 1 tells us: if there is a number division \ (5 \) remainder \ (3 \), there are two other numbers divided by \ (5, then the sum of the three numbers satisfies the Division \ (5 \) remainder \ (3 \)
Then, we construct three numbers \ (a, B, c \) to satisfy these three equations respectively, and can be divisible by the other two numbers, then \ (A + B + C \) is a solution to this equations.

Therefore, this problem is transformed into a simple problem: Find a \ (x \), so that \ (x \ bmod 3 = 0, x \ bmod 7 = 0 \) and \ (x \ bmod 5 = 3 \)
Obviously, X will be a multiple of \ (3*7 = 21 \), so we can simply consider \ (K * 21) \ bmod 5 = 3. ByNature 2As we can see, we only need to increase \ (21 \ bmod 5 \) to \ (5 \ times d)/(21 \ bmod 5) \) times, this value is the value of \ (k \).

The above problem (taking the ontology as an example) is equivalent to solving a \ (x \) problem so that \ (1 * x = 3 \ pmod 5 \) can be solved throughExtended Euclidean algorithm solution

Taking the ontology as an example, we write out the computing process.

  1. FindMinimum Public multiple: \ (LCM = 3*5*7 = 105 \)
  2. Find the corresponding numberBase Number:
    For the first condition, we have \ (105/3 = 35 \), \ (35 \ bmod 3 = 2 \), then the base number is \ (35 \)
    For the second condition, we have \ (105/5 = 21 \), \ (21 \ bmod 5 = 1 \) does not meet, multiply this formula \ (3 \), make \ (63 \ bmod 5 = 3 \) The base number \ (63 \)
    For the third condition, \ (105/7 = 15 \), \ (15 \ bmod 7 = 1 \) does not meet, which is the same as the previous step, multiplication \ (2 \) the base number is \ (30 \)
    Add the base number \ (35 + 63 + 30 = 128 \)
  3. Subtract the least public multiple (when the ratio is greater than the least public multiple)
    \ (X = 128-105 = 23 \)
Mathematical Model

Set \ (M_1, M_2, \ cdots, M_n \) to an integer of mutual quality, \ (M = \ prod _ {I = 1} ^ nm_ I, m_ I = m/m_ I \), \ (t_ I \) is a solution of the linear homogeneous equation \ (m_it_ I = 1 \ pmod m_ I \), for any \ (n \) number \ (A_1, A_2, \ cdots, a_n \), equations \ [x = a_ I \ pmod m_ I \] have integer solutions, returns the \ (x = \ sum _ {I = 1} ^ na_im_it_ I \)

Proof

\ (M_ I = m/m_ I \) is a multiple of all unexpected numbers except \ (m_ I \), SO \ (\ forall k \ not = I, a_im_it_ I = 0 \ pmod m_k \), and \ (x \) is introduced because \ (a_im_it_ I = a_ I \ pmod m_ I \). The original equation is true.

Code

Not streamlined yet

China Remainder Theorem

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.