The Chinese remainder theorem
Combine compatible residue constraints and prove both construction and uniqueness of the resulting class.
On this page
The question for today
What you’ll understand
- Construct a simultaneous solution for coprime moduli.
- Prove uniqueness modulo the product using divisibility.
- Handle noncoprime moduli with a compatibility condition.
A single integer can leave different remainders when measured against different packet sizes. Rather than guessing integers until all conditions happen to fit, the Chinese remainder theorem gives a reconstruction procedure. Coprime moduli are independent coordinates: any choice of their residues specifies one class modulo their product. When moduli share factors, independence fails in a precise way. We will learn both the clean independent case and the compatibility test that keeps the general case honest.
Build a selector for each coordinate
Suppose m and n are coprime positive integers, both at least two, and require x congruent to a modulo m and to b modulo n. Since n is invertible modulo m, choose u with nu congruent to one modulo m. Likewise choose v with mv congruent to one modulo n. The quantity nu behaves like one in the first coordinate and zero in the second; mv does the reverse.
Multiply these selectors by the desired residues and add. Reducing the expression modulo m kills the second term and leaves a, while reduction modulo n leaves b. This constructs a solution for every pair of target residues. The construction works with negative coefficients as well as positive ones, and reducing at the end to a representative between zero and mn − 1 is a convenience rather than an extra mathematical restriction.
Why there is exactly one combined class
If x and y solve the same pair of congruences, both m and n divide x − y. Coprimality then implies mn divides x − y. Thus all solutions lie in a single class modulo mn, and every member of that class is again a solution. The theorem promises uniqueness of a residue class, not a unique integer; there are infinitely many integer representatives separated by the product.
For more than two pairwise coprime moduli, combine two constraints and then combine the result with the next. Alternatively, make one selector per modulus by multiplying all the others and inverting that product in its own coordinate. Pairwise coprimality matters: merely having no prime common to the entire list is insufficient. The moduli six, ten, and fifteen have overall gcd one but are not independent in pairs.
Shared factors impose compatibility
For arbitrary m and n let d be their gcd. Any simultaneous solution must satisfy a congruent to b modulo d, since d divides both x − a and x − b. Conversely, if d divides b − a, set x = a + mt and solve mt congruent to b − a modulo n. If n/d = 1, the second constraint is automatic once compatibility holds. Otherwise division by d produces an invertible coefficient modulo n/d. Thus the compatibility condition is sufficient in both cases.
In this general case the solution class has period lcm(m, n), not necessarily mn. The product can overcount the same information because both moduli contain a shared constraint. This perspective is useful for periodic schedules, reconstruction from residues, and splitting computations into smaller pieces. Reconstruction does not magically recover an unbounded unknown integer: a range bound or a chosen class is still needed to turn the modular answer into a single measured value.
Work it through
Reconstruct two small residues
Find every integer satisfying x ≡ 2 modulo 5 and x ≡ 3 modulo 7.
Write x = 2 + 5t to satisfy the first condition automatically. The second becomes 5t ≡ 1 modulo 7, because 3 − 2 = 1.
Since 5 × 3 ≡ 1 modulo 7, t ≡ 3 modulo 7. Substitution gives x = 2 + 5(3 + 7k) = 17 + 35k for integer k.
Check 17 leaves remainder 2 on division by 5 and remainder 3 on division by 7. Any difference between two solutions is divisible by both coprime moduli, hence by 35.
The complete solution is x ≡ 17 modulo 35. A range restriction of 0 ≤ x < 35 would select the representative 17.
The living notebook
Explore the model
Interactive lab · modular
Inspect the reduced CRT equation
The worked example reduces reconstruction to 5t ≡ 1 modulo 7. Pause and reset the lab, then set both controls to modulus m = 7 and additive step a = 5; predict the orbit 0, 5, 3, 1 reaches the target at index three. Play or step to check, then reconstruct x = 2 + 5 × 3 = 17 by hand. The instrument displays this single additive orbit; it does not accept both original congruences or automatically solve a general CRT system.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forCRT reconstruction can reduce to finding one target on an additive residue orbit, followed by substitution into the first congruence.
Pause & reason
Check your understanding
Your turn
Try it yourself
Solve x ≡ 4 modulo 6 and x ≡ 6 modulo 8. State the correct period and verify the smallest nonnegative solution.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The shared gcd is two. Substitute x = 4 + 6t before reducing the second congruence.
Compare with the solution
Compatibility holds because 4 and 6 have the same parity. Substitution gives 6t ≡ 2 modulo 8, or 3t ≡ 1 modulo 4 after division by 2. The inverse of 3 modulo 4 is 3, so t = 3 + 4k. Therefore x = 22 + 24k. The representative 22 leaves remainders 4 and 6 as required, and the period is lcm(6, 8) = 24 rather than the product 48.
Keep the idea
Take it with you
- Coprime residue coordinates can be selected and reconstructed independently.
- Uniqueness is modulo the combined period, not uniqueness as an integer.
- Shared factors require compatible residues and replace the product period by the lcm.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.