Chinese Remainder Theorem
Last updated
Last updated
The Chinese Remainder Theorem (CRT) is a mathematical theorem that states that if we have a system of linear congruences (equations of the form "x ≡ a mod m
") with pairwise coprime moduli, then there exists a unique solution for x
modulo the product of the moduli.
The theorem is called "Chinese" because it was first stated by the ancient Chinese mathematician Sun Tzu Suan Ching.
The CRT is particularly useful in solving systems of simultaneous modular equations that are difficult or impossible to solve individually. For example, if we have two congruences:
It is not possible to find a single solution for x
that satisfies both congruences.
However, using the CRT, we can find a unique solution for x
that satisfies both congruences modulo the product of the moduli (20
).
In order to calculate a solution, two variables are needed :
For each elements of E
, the inverse (mod ni
) y
can be calculated using the :
Then a solution for x can be calculated using the following equation :
The unique solution is then x % N