The Chinese Remainder Theorem (CRT)
If the moduli m1,m2,…,mk are pairwise coprime (any two share no common factor), then the system of congruences
x≡a1(modm1),x≡a2(modm2),…,x≡ak(modmk)
has a unique solution modulo M=m1×m2×⋯×mk.
Step-by-step: Solve the system
x≡2(mod3),x≡3(mod5),x≡2(mod7)
Step 1 — Check pairwise coprimality. gcd(3,5)=1, gcd(3,7)=1, gcd(5,7)=1. ✓
Step 2 — Compute M. M=3×5×7=105.
Step 3 — Compute partial products. M1=M/m1=105/3=35, M2=105/5=21, M3=105/7=15.
Step 4 — Find modular inverses. We need Mi−1(modmi) (the number yi such that Mi⋅yi≡1(modmi)):
35y1≡1(mod3): 35≡2(mod3), and 2×2=4≡1(mod3). So y1=2.
21y2≡1(mod5): 21≡1(mod5), so y2=1.
15y3≡1(mod7): 15≡1(mod7), so y3=1.
Step 5 — Combine.
x=a1M1y1+a2M2y2+a3M3y3
=2×35×2+3×21×1+2×15×1
=140+63+30=233
Step 6 — Reduce mod M. 233mod105=233−2×105=23.
x≡23(mod105)
Verification: 23mod3=2 ✓, 23mod5=3 ✓, 23mod7=2 ✓.
Intuition: why 23 works
23 is the unique number between 0 and 104 that simultaneously leaves remainder 2 when divided by 3, remainder 3 when divided by 5, and remainder 2 when divided by 7. Adding 105 to 23 gives 128, which also satisfies all three — the solution repeats every 105.
Try it in the visualization
Enter the remainders and moduli. The CRT construction is animated step by step. The solution is verified against all congruences. A number line shows the periodic solutions.