Introduction to China Residue Theorem
In Sun Tzu's computing Sutra, there is a problem: "I don't know the number of things today, but the number of three is two (divided by more than three 2 ), three of the five remaining values (divided by more than 5 3), two of the seven remaining values (divided by more than 7 2), and asked ry?" This problem is called the "Sun Tzu's Problem". The general solution of this problem is internationally referred to as the "China Surplus Theorem ". The solution consists of three steps:
- Find three numbers: Find the minimum number 15 after 7 division of 1 from the public multiples of 3 and 5, and find the minimum number 21 after 5 Division of 1 from the public multiples of 3 and 7, finally, find the minimum number of 70 except 3 and 1 from the public multiples of 5 and 7.
- Multiply by 15 by 2 (2 is the remainder of the final result divided by 7) and 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.
- Divide 233 by 3, 5, and 7 by the minimum public multiple of 105, and obtain the remainder 23, that is, 233% 105 = 23. The remainder 23 is the minimum number that meets the condition.
Analysis:
We split the "Sun Tzu's question" into several simple small problems, starting from scratch, trying to speculate on how the ancients pushed this solution.
First, let us assume that N1 is a number that satisfies dividing by 3 more than 2, such as 2, 5, 8, and so on, that is, an arbitrary number that satisfies 3 * k + 2 (k> = 0. Similarly, we assume that N2 is a number that satisfies the division by more than 5 3, and N3 is a number that satisfies the division by more than 7 2.
With the preceding assumption, we first start from the perspective of N1. If we know that N1 is satisfied by dividing by 3 + 2, can we make the sum of N1 + N2 still meet the condition of dividing by 3 + 2? So that the sum of N1 + N2 + N3 is still divided by 3 + 2?
This involves a basic mathematical theorem. If a % B = C exists, (a + kb) % B = C (K is a non-zero integer). In other words, if the remainder of a division operation is C, the sum (difference) of the addition (or subtraction) of the divisor and K times is then divided with the divisor, and the remainder remains unchanged. This is a good proof.
Based on this theorem, if N2 is a multiple of 3, N1 + N2 can still be divided by 3 + 2. Similarly, if N3 is a multiple of 3, the sum of N1 + N2 + N3 is divided by 3 and 2. This is from the perspective of N1. From the perspective of N2 and N3, we can export the following three points:
- In order to divide the sum of N1 + N2 + N3 by 3 + 2, N2 and N3 must be multiples of 3.
- In order to divide the sum of N1 + N2 + N3 by more than 5 3, N1 and N3 must be multiples of 5.
- To divide the sum of N1 + N2 + N3 by more than 7 2, N1 and N2 must be multiples of 7.
Therefore, to enable the sum of N1 + N2 + N3 as a final solution to the "Sun Tzu problem", we need to meet the following requirements:
- N1 is divided by more than 3 2 and is a public multiple of 5 and 7.
- N2 is divided by more than 5 3 and is a public multiple of 3 and 7.
- N3 is divided by more than 7 2 and is a public multiple of 3 and 5.
Therefore, the essence of Sun Tzu's solution is to find a number N1 divided by 3 and 2 in the public multiples of 5 and 7, find a number N2 divided by more than 5 3 from the public multiples of 3 and 7, and find a number N3 divided by more than 7 2 from the public multiples of 3 and 5, then, add the three numbers to obtain the solution. I used a small trick to evaluate N1, N2, and N3. Taking N1 as an example, we did not directly find a number divided by 3 and 2 from the public multiples of 5 and 7, instead, first find a number divided by 3 and then multiply by 2.
Here is another mathematical formula. If a % B = C, (A * k) % B = A % B +... + A % B = C +... + C = Kc (k> 0). That is to say, if the remainder of a division is C, the remainder of the devisor K times the division is KC. Proof in expansion.
Finally, we need to be clear that N1 + N2 + N3 is only a solution to the problem, not the smallest solution. How do I obtain the explain solution? We only need to minimize the loss of the Public multiples of 3, 5, and 7 by 105. The truth is the previous theorem "if a % B = C, there is (a-KB) % B = C ". Therefore (N1 + N2 + N3) % 105 is the final solution.