The Chinese remainder theorem can be used to solve systems
of congruences like:
x≡a1x≡ak(modm1)⋮(modmn)
Let
m1,...,mn
be integers greater than 1, these are called the moduli or
divisors. Let
m
be the product of all
mk.
The theorem than states that if all
mk
are pairwise coprime and all
ak
are integers such that
0≤ak<mk,
than there is a unique solution
x(modm).
Generic solution
To solve a system of congruences, first let
m=m1⋅m2⋅…⋅mn
Next, for
k=1,2,…,n
let
Mk=mkm
In other words,
Mk
is the product of all the moduli, except
mk.
Now for every
Mk,
find it’s inverse
yk,
such that:
Mk⋅yk≡1(modmk)
To find the solution
x
of the system, compute
x=a1M1y1+a2M2y2+…+anMnynmodm
Example
Find a solution for the following system of congruences:
xxx≡0(mod3)≡1(mod5)≡2(mod8)
First calculate
m:
m=3⋅5⋅8=120
Next determine all
Mk:
M1M2M3=m1m=3120=40=m2m=5120=24=m3m=8120=15
Now find the inverse of every
Mk:
M1⋅y140⋅y1y1M2⋅y224⋅y2y2M3⋅y315⋅y3y3≡1(modm1)≡1(mod3)=1≡1(modm2)≡1(mod5)=4≡1(modm3)≡1(mod8)=7
Next we compute the solution
x:
xxxxx=a1M1y1+a2M2y2+a3M3y3modm=0⋅40⋅1+1⋅24⋅4+2⋅15⋅7mod120=0+96+210mod120=306mod120=66