Intuition What this page is
The Chinese Remainder Theorem (intro) gave you a formula. But formulas hide traps: what if a remainder is zero ? What if the remainders are bigger than the moduli? What if the moduli share a factor (so CRT "shouldn't" apply)? What if a coefficient is negative ?
This page is a map of every case you can meet, and one fully-worked example for each square on the map. If you can do all of these, no exam question about combining congruences can surprise you.
We will lean on three prerequisite ideas, so let us name them once:
Congruence x ≡ a ( mod m ) means "x and a leave the same remainder when divided by m " — equivalently, m divides x − a . (See Modular Arithmetic Basics .)
Modular inverse of b modulo m is the number b − 1 with b ⋅ b − 1 ≡ 1 ( mod m ) . It exists exactly when g cd( b , m ) = 1 , and we find it with the Extended Euclidean Algorithm (which is really Bezout's Identity in action).
Pairwise coprime moduli: every pair shares no common factor bigger than 1.
lcm ("least common multiple") of two numbers is the smallest positive integer that both divide into. For example lcm ( 4 , 6 ) = 12 . When moduli are coprime, lcm ( m 1 , m 2 ) = m 1 m 2 ; when they share a factor it is smaller. We only need it in the non-coprime cases (F below).
Every coprime example on this page runs the same five-step machine . Restate it once so we never apply it by rote.
Intuition WHY the sum works — the "on/off switch" idea
Look at a single term a i M i y i and ask what it does in each congruence :
Modulo m i (its own line): M i y i ≡ 1 by the choice of y i , so the term is ≡ a i ⋅ 1 = a i . It contributes exactly the remainder we wanted.
Modulo m j for any other line (j = i ): M i = M / m i still contains the factor m j , so M i ≡ 0 ( mod m j ) , killing the whole term.
So each term is a switch : fully ON (equals a i ) in its own congruence, and OFF (equals 0 ) in every other. Adding all the switches gives a number that reads a 1 mod m 1 , a 2 mod m 2 , and so on — exactly the solution. The diagram in Example 1 shows this switching geometrically.
The mnemonic for the five steps (M ultiply–D ivide–I nvert–A dd–R educe) appears at the foot of the page.
Think of a CRT problem as a machine with dials. Each dial can be set to an "ordinary" position or an "edge" position. The table below lists every dial and its edge positions — and which example switches that dial.
#
Case class (the dial)
What is unusual
Example
A
Standard, two congruences
nothing — the baseline
Ex 1
B
Standard, three congruences
more equations, sum of three terms
Ex 2
C
A remainder is 0
a i = 0 : "x divisible by m i "
Ex 3
D
Remainder ≥ modulus / negative
need to reduce a i first
Ex 4
E
Inverse is genuinely hard
must run Extended Euclid, not guess
Ex 5
F
Non-coprime, consistent
g cd> 1 but no conflict — the generalized case
Ex 6
G
Non-coprime, contradictory
no solution exists at all
Ex 7
H
Word problem (real world)
translate English into congruences
Ex 8
I
Exam twist (extra unknown)
find the value , given a range, not just the class
Ex 9
Every numeric answer below is machine-checked. Let us walk the map.
Worked example Example 1 (Cell A): two congruences
Solve
{ x ≡ 2 ( mod 3 ) x ≡ 4 ( mod 7 )
Forecast: guess a number that is 2 more than a multiple of 3 and 4 more than a multiple of 7 before reading on. (Try listing 4 , 11 , 18 , 25 , … and testing each mod 3 .)
Step 1 — Check the moduli are coprime. g cd( 3 , 7 ) = 1 . ✓
Why this step? CRT's uniqueness and the inverses only work when moduli share no factor. If this failed we would be in Case F or G.
Step 2 — Total modulus. M = 3 ⋅ 7 = 21 .
Why? The answer will be unique in the window 0 ≤ x < 21 ; everything else is this answer plus multiples of 21 .
Step 3 — Partial products M i = M / m i . M 1 = 21/3 = 7 , M 2 = 21/7 = 3 .
Why? M 1 is divisible by every modulus except m 1 , so its term will vanish in every congruence but the first — that is the whole trick.
Step 4 — Inverses y i = M i − 1 mod m i .
7 y 1 ≡ 1 ( mod 3 ) . Since 7 ≡ 1 , we need y 1 ≡ 1 , so y 1 = 1 .
3 y 2 ≡ 1 ( mod 7 ) . Try 3 ⋅ 5 = 15 ≡ 1 , so y 2 = 5 .
Why? M i y i ≡ 1 makes the i -th term contribute exactly a i , not a i times some stray factor.
Step 5 — Assemble.
x ≡ a 1 M 1 y 1 + a 2 M 2 y 2 = 2 ⋅ 7 ⋅ 1 + 4 ⋅ 3 ⋅ 5 = 14 + 60 = 74 ≡ 74 − 3 ⋅ 21 = 11 ( mod 21 )
Why this combination? By the on/off switch idea above: the term 2 ⋅ 7 ⋅ 1 reads 2 mod 3 and 0 mod 7 ; the term 4 ⋅ 3 ⋅ 5 reads 0 mod 3 and 4 mod 7 . Their sum therefore reads 2 mod 3 and 4 mod 7 — precisely the system.
Verify: 11 = 3 ⋅ 3 + 2 ⇒≡ 2 ( mod 3 ) ✓; 11 = 1 ⋅ 7 + 4 ⇒≡ 4 ( mod 7 ) ✓.
Answer: x ≡ 11 ( mod 21 ) .
Reading the figure below (alt: a 3 × 7 grid of the numbers 0 –20 ; the row is the remainder mod 3 , the column the remainder mod 7 ). Because 3 and 7 are coprime, every number 0 –20 lands in a different cell — all 21 cells are filled exactly once. Our first congruence "x ≡ 2 ( mod 3 ) " selects the pink row (remainder 2 ); the second "x ≡ 4 ( mod 7 ) " selects the blue column (remainder 4 ). They cross in exactly one cell , highlighted yellow, holding the number 11 — the same x our algebra produced. This is the geometric meaning of "unique solution modulo 21 ": one row-times-column crossing per window.
Worked example Example 2 (Cell B): three at once
Solve
⎩ ⎨ ⎧ x ≡ 2 ( mod 3 ) x ≡ 3 ( mod 4 ) x ≡ 1 ( mod 5 )
Forecast: the answer lives in [ 0 , 60 ) . Guess whether it is nearer 0 or 60 .
Step 1 — Coprime check. g cd( 3 , 4 ) = g cd( 3 , 5 ) = g cd( 4 , 5 ) = 1 ✓.
Step 2 — M = 3 ⋅ 4 ⋅ 5 = 60 .
Step 3 — Partial products. M 1 = 20 , M 2 = 15 , M 3 = 12 .
Why? Each drops exactly one modulus, so M i is divisible by the other two moduli.
Step 4 — Inverses.
20 y 1 ≡ 1 ( mod 3 ) : 20 ≡ 2 , need 2 y 1 ≡ 1 , y 1 = 2 .
15 y 2 ≡ 1 ( mod 4 ) : 15 ≡ 3 , need 3 y 2 ≡ 1 , y 2 = 3 .
12 y 3 ≡ 1 ( mod 5 ) : 12 ≡ 2 , need 2 y 3 ≡ 1 , y 3 = 3 .
Step 5 — Assemble.
x ≡ 2 ⋅ 20 ⋅ 2 + 3 ⋅ 15 ⋅ 3 + 1 ⋅ 12 ⋅ 3 = 80 + 135 + 36 = 251 ≡ 251 − 4 ⋅ 60 = 11 ( mod 60 )
Why this combination? Same on/off switch idea, now with three switches: 2 ⋅ 20 ⋅ 2 reads 2 mod 3 and 0 mod 4 , 5 ; 3 ⋅ 15 ⋅ 3 reads 3 mod 4 and 0 mod 3 , 5 ; 1 ⋅ 12 ⋅ 3 reads 1 mod 5 and 0 mod 3 , 4 . The sum inherits one live remainder from each.
Verify: 11 ≡ 2 ( mod 3 ) ✓; 11 ≡ 3 ( mod 4 ) ✓; 11 ≡ 1 ( mod 5 ) ✓.
Answer: x ≡ 11 ( mod 60 ) — near the bottom of the window.
Worked example Example 3 (Cell C):
a i = 0
Solve
{ x ≡ 0 ( mod 4 ) x ≡ 3 ( mod 5 )
Forecast: "x ≡ 0 ( mod 4 ) " just means x is a multiple of 4 . Does a zero remainder break the formula? (Guess: no — but why?)
Step 1 — Coprime. g cd( 4 , 5 ) = 1 ✓.
Step 2 — M = 20 .
Step 3 — M 1 = 5 , M 2 = 4 .
Step 4 — Inverses.
5 y 1 ≡ 1 ( mod 4 ) : 5 ≡ 1 , y 1 = 1 .
4 y 2 ≡ 1 ( mod 5 ) : 4 ⋅ 4 = 16 ≡ 1 , y 2 = 4 .
Step 5 — Assemble.
x ≡ = 0 0 ⋅ 5 ⋅ 1 + 3 ⋅ 4 ⋅ 4 = 48 ≡ 48 − 2 ⋅ 20 = 8 ( mod 20 )
Why this combination? The switch idea again: the first term would read a 1 mod 4 , but here a 1 = 0 , so that switch is turned off to 0 everywhere. The second term reads 3 mod 5 and 0 mod 4 . Their sum reads 0 mod 4 and 3 mod 5 — the system.
Verify: 8 = 2 ⋅ 4 ⇒≡ 0 ( mod 4 ) ✓; 8 = 1 ⋅ 5 + 3 ⇒≡ 3 ( mod 5 ) ✓.
Answer: x ≡ 8 ( mod 20 ) .
Worked example Example 4 (Cell D): reduce
a i first
Solve
{ x ≡ 9 ( mod 5 ) x ≡ − 1 ( mod 6 )
Forecast: a remainder of 9 modulo 5 ? A negative remainder − 1 ? Neither is in the "normal" range 0 ≤ a < m . What is the honest way to fix this?
Step 0 — Normalise the remainders.
9 ≡ 9 − 5 = 4 ( mod 5 ) , so the first line is really x ≡ 4 ( mod 5 ) .
− 1 ≡ − 1 + 6 = 5 ( mod 6 ) , so the second is x ≡ 5 ( mod 6 ) .
Why this step? ≡ only cares about the remainder; we may add or subtract the modulus freely. Doing this first stops arithmetic slips later. (This is pure Modular Arithmetic Basics .)
Step 1 — Coprime. g cd( 5 , 6 ) = 1 ✓.
Step 2 — M = 30 .
Step 3 — M 1 = 6 , M 2 = 5 .
Step 4 — Inverses.
6 y 1 ≡ 1 ( mod 5 ) : 6 ≡ 1 , y 1 = 1 .
5 y 2 ≡ 1 ( mod 6 ) : 5 ⋅ 5 = 25 ≡ 1 , y 2 = 5 .
Step 5 — Assemble (using the reduced remainders 4 and 5 ):
x ≡ 4 ⋅ 6 ⋅ 1 + 5 ⋅ 5 ⋅ 5 = 24 + 125 = 149 ≡ 149 − 4 ⋅ 30 = 29 ( mod 30 )
Why this combination? Each term is again a switch: 4 ⋅ 6 ⋅ 1 reads 4 mod 5 and 0 mod 6 ; 5 ⋅ 5 ⋅ 5 reads 5 mod 6 and 0 mod 5 . The sum reads the reduced remainders on each line.
Verify: 29 = 5 ⋅ 5 + 4 ⇒≡ 4 ≡ 9 ( mod 5 ) ✓; 29 = 4 ⋅ 6 + 5 ⇒≡ 5 ≡ − 1 ( mod 6 ) ✓.
Answer: x ≡ 29 ( mod 30 ) .
Worked example Example 5 (Cell E): no lucky guess
Solve
{ x ≡ 4 ( mod 11 ) x ≡ 9 ( mod 13 )
Forecast: the inverses here are not small. We will earn them with the Extended Euclidean Algorithm .
Step 1 — Coprime. 11 , 13 are distinct primes, g cd= 1 ✓.
Step 2 — M = 143 .
Step 3 — M 1 = 13 , M 2 = 11 .
Step 4 — Inverses by Extended Euclid.
Need 13 y 1 ≡ 1 ( mod 11 ) , i.e. 2 y 1 ≡ 1 ( mod 11 ) (since 13 ≡ 2 ). Extended Euclid on 2 , 11 : 2 ⋅ 6 = 12 = 11 + 1 , so 2 ⋅ 6 ≡ 1 . Thus y 1 = 6 .
Need 11 y 2 ≡ 1 ( mod 13 ) . Run Euclid: 13 = 1 ⋅ 11 + 2 , 11 = 5 ⋅ 2 + 1 . Back-substitute (this is Bezout's Identity ): 1 = 11 − 5 ⋅ 2 = 11 − 5 ( 13 − 11 ) = 6 ⋅ 11 − 5 ⋅ 13 . So 11 ⋅ 6 ≡ 1 ( mod 13 ) , giving y 2 = 6 .
Why Extended Euclid and not trial? For a modulus like 13 , guessing wastes time and hides errors. Euclid's back-substitution produces the Bezout combination 6 ⋅ 11 − 5 ⋅ 13 = 1 , which is the inverse, provably.
Step 5 — Assemble.
x ≡ 4 ⋅ 13 ⋅ 6 + 9 ⋅ 11 ⋅ 6 = 312 + 594 = 906 ≡ 906 − 6 ⋅ 143 = 906 − 858 = 48 ( mod 143 )
Why this combination? The switch idea once more: 4 ⋅ 13 ⋅ 6 reads 4 mod 11 (since 13 ⋅ 6 ≡ 1 ) and 0 mod 13 ; 9 ⋅ 11 ⋅ 6 reads 9 mod 13 and 0 mod 11 . Their sum matches both lines.
Verify: 48 = 4 ⋅ 11 + 4 ⇒≡ 4 ( mod 11 ) ✓; 48 = 3 ⋅ 13 + 9 ⇒≡ 9 ( mod 13 ) ✓.
Answer: x ≡ 48 ( mod 143 ) .
The intro note warned that the plain formula fails when moduli share a factor. But solutions can still exist — you just need the compatibility check. This is the generalized CRT .
Definition Generalized compatibility condition
For x ≡ a 1 ( mod m 1 ) and x ≡ a 2 ( mod m 2 ) with g = g cd( m 1 , m 2 ) , a solution exists iff a 1 ≡ a 2 ( mod g ) . When it exists it is unique modulo lcm ( m 1 , m 2 ) (the lcm , least common multiple, defined at the top of the page).
Worked example Example 6 (Cell F): shared factor, still solvable
Solve
{ x ≡ 3 ( mod 4 ) x ≡ 5 ( mod 6 )
Forecast: g cd( 4 , 6 ) = 2 . Both say x is odd (3 is odd mod 4 , 5 is odd mod 6 ). Compatible? Guess yes — then find it.
Step 1 — Compatibility. g = g cd( 4 , 6 ) = 2 . Check a 1 ≡ a 2 ( mod 2 ) : 3 ≡ 1 and 5 ≡ 1 , so 3 ≡ 5 ( mod 2 ) ✓. A solution exists.
Why this step? Both congruences constrain x mod 2 . If they disagreed there (Case G), no x could satisfy both.
Step 2 — Merge by hand. From line one, x = 3 + 4 k . Substitute into line two:
3 + 4 k ≡ 5 ( mod 6 ) ⇒ 4 k ≡ 2 ( mod 6 ) .
Now divide the whole congruence — both sides and the modulus — by g = 2 , giving 2 k ≡ 1 ( mod 3 ) .
Why is dividing by g legal? A congruence c a ≡ c b ( mod c n ) literally says c n ∣ ( c a − c b ) , i.e. c n ∣ c ( a − b ) . Cancel the common factor c from both the divisor and the quantity divided: this is equivalent to n ∣ ( a − b ) , that is a ≡ b ( mod n ) . So dividing sides and modulus by their shared factor c preserves truth exactly. Here c = 2 : 4 k ≡ 2 ( mod 6 ) becomes 2 k ≡ 1 ( mod 3 ) . (Note: you may only cancel a factor from a modulus when it also divides both sides — cancelling from sides alone is a different, riskier rule.)
Now 2 − 1 ≡ 2 ( mod 3 ) , so k ≡ 2 ⋅ 1 = 2 ( mod 3 ) , i.e. k = 2 + 3 t .
Step 3 — Back-substitute. x = 3 + 4 ( 2 + 3 t ) = 11 + 12 t . So x ≡ 11 ( mod 12 ) , and 12 = lcm ( 4 , 6 ) .
Verify: 11 = 2 ⋅ 4 + 3 ⇒≡ 3 ( mod 4 ) ✓; 11 = 1 ⋅ 6 + 5 ⇒≡ 5 ( mod 6 ) ✓.
Answer: x ≡ 11 ( mod 12 ) — unique modulo the lcm , not the product.
Worked example Example 7 (Cell G): no solution
Solve
{ x ≡ 2 ( mod 4 ) x ≡ 3 ( mod 6 )
Forecast: x ≡ 2 ( mod 4 ) makes x even ; x ≡ 3 ( mod 6 ) makes x odd . Can a number be both?
Step 1 — Compatibility. g = g cd( 4 , 6 ) = 2 . Need a 1 ≡ a 2 ( mod 2 ) : 2 ≡ 0 but 3 ≡ 1 , and 0 ≡ 1 ( mod 2 ) . Fails.
Why this is the whole story: the two lines demand different parities of x . No integer is both even and odd, so the system is inconsistent .
Step 2 — Conclusion. No solution exists. Writing the CRT formula would require inverting M 1 = 6 modulo m 1 = 4 , but g cd( 6 , 4 ) = 2 , so that inverse does not exist — the algebra refuses, exactly matching the parity clash.
Verify: search x = 0 , … , 11 : none satisfies both (checked in VERIFY). ✓ (empty solution set confirmed)
Answer: No solution.
Common mistake Do not skip the compatibility check
When moduli are coprime, compatibility is automatic (g = 1 , everything is ≡ mod 1 ). It is only when g cd> 1 that you must test a i ≡ a j ( mod g cd) before grinding the algebra. Cases F and G differ by exactly this test.
Worked example Example 8 (Cell H): the basket puzzle
A basket holds fewer than 100 eggs. Counting them in groups of 5 leaves 3 over; in groups of 6 leaves 4 over; in groups of 7 leaves 1 over. How many eggs?
Forecast: the answer is a single number below 100 . Guess a rough size before solving.
Step 1 — Translate. Let x = number of eggs.
x ≡ 3 ( mod 5 ) , x ≡ 4 ( mod 6 ) , x ≡ 1 ( mod 7 ) .
Why? "Leaves 3 over when grouped in 5s" is literally "remainder 3 mod 5."
Step 2 — Coprime? g cd( 5 , 6 ) = g cd( 5 , 7 ) = g cd( 6 , 7 ) = 1 ✓, so standard CRT applies. M = 5 ⋅ 6 ⋅ 7 = 210 .
Step 3 — Partial products. M 1 = 42 , M 2 = 35 , M 3 = 30 .
Step 4 — Inverses.
42 y 1 ≡ 1 ( mod 5 ) : 42 ≡ 2 , 2 y 1 ≡ 1 , y 1 = 3 .
35 y 2 ≡ 1 ( mod 6 ) : 35 ≡ 5 , 5 y 2 ≡ 1 , y 2 = 5 .
30 y 3 ≡ 1 ( mod 7 ) : 30 ≡ 2 , 2 y 3 ≡ 1 , y 3 = 4 .
Step 5 — Assemble.
x ≡ 3 ⋅ 42 ⋅ 3 + 4 ⋅ 35 ⋅ 5 + 1 ⋅ 30 ⋅ 4 = 378 + 700 + 120 = 1198 ( mod 210 ) .
Why this combination? Three switches: 3 ⋅ 42 ⋅ 3 reads 3 mod 5 only; 4 ⋅ 35 ⋅ 5 reads 4 mod 6 only; 1 ⋅ 30 ⋅ 4 reads 1 mod 7 only. The sum reads all three remainders at once.
1198 − 5 ⋅ 210 = 1198 − 1050 = 148 , so x ≡ 148 ( mod 210 ) .
Step 6 — Apply the real-world constraint. "Fewer than 100 eggs" — but 148 > 100 and the next candidate down is 148 − 210 < 0 . So the only value in [ 0 , 210 ) is 148 , which violates "< 100 ."
Verify: 148 = 29 ⋅ 5 + 3 ⇒≡ 3 ( mod 5 ) ✓; 148 = 24 ⋅ 6 + 4 ⇒≡ 4 ( mod 6 ) ✓; 148 = 21 ⋅ 7 + 1 ⇒≡ 1 ( mod 7 ) ✓.
Answer: the congruences force x ≡ 148 ( mod 210 ) ; there is no valid count below 100 (the smallest positive solution is 148 ). Lesson: CRT gives the residue class; the word problem's range then filters which member (if any) is legal.
Worked example Example 9 (Cell I): pin down the exact value
An integer N satisfies N ≡ 1 ( mod 3 ) , N ≡ 4 ( mod 5 ) , and N ≡ 6 ( mod 7 ) . Given that 200 ≤ N ≤ 300 , find N exactly.
Forecast: CRT gives a class mod 105 ; the range [ 200 , 300 ] selects one member. Which?
Step 1 — M = 3 ⋅ 5 ⋅ 7 = 105 .
Step 2 — M 1 = 35 , M 2 = 21 , M 3 = 15 .
Step 3 — Inverses.
35 y 1 ≡ 1 ( mod 3 ) : 35 ≡ 2 , need 2 y 1 ≡ 1 , y 1 = 2 .
21 y 2 ≡ 1 ( mod 5 ) : 21 ≡ 1 , so y 2 = 1 .
15 y 3 ≡ 1 ( mod 7 ) : 15 ≡ 1 , so y 3 = 1 .
Step 4 — Assemble.
N ≡ 1 ⋅ 35 ⋅ 2 + 4 ⋅ 21 ⋅ 1 + 6 ⋅ 15 ⋅ 1 = 70 + 84 + 90 = 244 ( mod 105 ) .
Why this combination? Three switches: 1 ⋅ 35 ⋅ 2 reads 1 mod 3 only; 4 ⋅ 21 ⋅ 1 reads 4 mod 5 only; 6 ⋅ 15 ⋅ 1 reads 6 mod 7 only. The sum reads all three.
244 − 2 ⋅ 105 = 34 , so N ≡ 34 ( mod 105 ) .
Step 5 — Select using the range. List the members of the class 34 , 139 , 244 , 349 , … (each is the previous plus 105 ). The one lying in [ 200 , 300 ] is 244 .
Why this step? CRT alone answers "which class"; the exam's extra interval answers "which representative." Without the interval the answer would just be "N ≡ 34 ( mod 105 ) ."
Verify: 244 = 81 ⋅ 3 + 1 ⇒≡ 1 ( mod 3 ) ✓; 244 = 48 ⋅ 5 + 4 ⇒≡ 4 ( mod 5 ) ✓; 244 = 34 ⋅ 7 + 6 ⇒≡ 6 ( mod 7 ) ✓; and 200 ≤ 244 ≤ 300 ✓.
Answer: N = 244 .
Recall Checklist: have you covered every dial?
A/B standard 2- and 3-congruence ::: Ex 1, Ex 2
C zero remainder ::: Ex 3 (term vanishes)
D oversized / negative remainder ::: Ex 4 (reduce first)
E hard inverse via Extended Euclid ::: Ex 5
F non-coprime consistent (answer mod lcm) ::: Ex 6
G non-coprime contradictory (no solution) ::: Ex 7
H word problem + range filter ::: Ex 8
I exam twist: select exact value in an interval ::: Ex 9
Mnemonic The five-step drill for coprime systems
M ultiply (get M ) → D ivide (get each M i ) → I nvert (get each y i ) → A dd (∑ a i M i y i ) → R educe (mod M ). "M y D og I s A lways R eady."
Recall Where this leads next
When one modulus is a product of two primes and you invert modulo it, you are doing exactly the step RSA Cryptography uses to speed up decryption via CRT. And the inverses you computed are guaranteed to exist by Fermat's Little Theorem / Bezout's Identity whenever moduli are coprime — see Systems of Linear Congruences for the fully general merge procedure used in Case F.
Which cases require the compatibility check a i ≡ a j ( mod g cd) ? Only non-coprime cases (F and G); coprime systems have g cd= 1 so it is automatic.
In a non-coprime consistent system, the solution is unique modulo what? lcm ( m 1 , m 2 ) , not the product m 1 m 2 .
Why does a zero remainder a i = 0 simplify the CRT sum? Its term a i M i y i = 0 drops out entirely.