Examples of Chinese Remainder Theorem algorithm implemented by Python and python theorem Algorithm
This example describes the Chinese Remainder Theorem algorithm implemented by Python. We will share this with you for your reference. The details are as follows:
Chinese Remainder Theorem-CRT: Also known as Sun Tzu's Theorem, It is a Theorem in number theory. That is, if a person knows the remainder obtained by dividing a number n by multiple integers, when these divisor is mutually qualitative, this person can uniquely determine the remainder obtained by dividing n by the product of these integers.
Wiki on Wikipedia: The Chinese remainder theorem is a theorem of number theory, which states that, if one knows the remainders of the division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.
There is a number of n, divided by 2, divided by 1, divided by 3, divided by 2, divided by 5, divided by 6, divided by 5, and is exactly divided by 7, calculate the number n.
Analysis: n is divided by 2 and the remainder 1 indicates that the minimum value is 1. After that, the condition is always satisfied, so the number to be added must be a multiple of 2. Divide 3 into 2, that is, (1 + 2 * I) % 3 = 2, where I is a positive integer. This condition is always met, so the number to be added must be a multiple of 3. Because of the limitation of the previous condition, it is an integer multiple of the minimum public multiples of 2 and 3. And so on, you can find the number divisible by 7.
N = 1 while (n % 3! = 2): n + = 2 while (n % 5! = 4): n + = 6 while (n % 6! = 5): n + = 30 while (n % 7! = 0): n + = 30
The result is 119.