2.5.10 · D3Number Theory (Intermediate)

Worked examples — Chinese Remainder Theorem (intro)

3,593 words16 min readBack to topic

We will lean on three prerequisite ideas, so let us name them once:

  • Congruence means " and leave the same remainder when divided by " — equivalently, divides . (See Modular Arithmetic Basics.)
  • Modular inverse of modulo is the number with . It exists exactly when , 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 . When moduli are coprime, ; when they share a factor it is smaller. We only need it in the non-coprime cases (F below).

The one formula we will reuse

Every coprime example on this page runs the same five-step machine. Restate it once so we never apply it by rote.

The mnemonic for the five steps (Multiply–Divide–Invert–Add–Reduce) appears at the foot of the page.


The scenario matrix

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 : " divisible by " Ex 3
D Remainder modulus / negative need to reduce first Ex 4
E Inverse is genuinely hard must run Extended Euclid, not guess Ex 5
F Non-coprime, consistent 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.


Case A — the baseline

Reading the figure below (alt: a grid of the numbers ; the row is the remainder mod , the column the remainder mod ). Because and are coprime, every number lands in a different cell — all cells are filled exactly once. Our first congruence "" selects the pink row (remainder ); the second "" selects the blue column (remainder ). They cross in exactly one cell, highlighted yellow, holding the number — the same our algebra produced. This is the geometric meaning of "unique solution modulo ": one row-times-column crossing per window.

Figure — Chinese Remainder Theorem (intro)

Case B — three congruences


Case C — a remainder is zero


Case D — remainder too big or negative


Case E — the inverse needs Extended Euclid


Case F — non-coprime but consistent

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.


Case G — non-coprime and contradictory


Case H — a word problem


Case I — the exam twist


The matrix, filled in

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

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 ?
Only non-coprime cases (F and G); coprime systems have so it is automatic.
In a non-coprime consistent system, the solution is unique modulo what?
, not the product .
Why does a zero remainder simplify the CRT sum?
Its term drops out entirely.