ARITHMETIC AND NUMBER THEORY
Chinese Remainder Theorem
The Chinese Remainder Theorem combines several remainder conditions into one repeating answer. When the moduli are pairwise coprime, any choices of remainders produce exactly one solution class modulo the product of those moduli. The method is useful for solving congruences, checking schedules, and understanding how modular arithmetic fits together.
THE THEOREM
One solution class for compatible remainders
Let m₁, m₂, …, mᵣ be pairwise coprime positive integers. For any integers a₁, a₂, …, aᵣ, the system below has a solution, and all solutions are congruent modulo the product M = m₁m₂⋯mᵣ.
In plain language: if you know the remainder of a number after division by several pairwise coprime numbers, there is one repeating pattern that satisfies all of those remainder rules. The answer repeats every M integers.
Read the remainder conditions
A congruence such as x ≡ 2 (mod 3) says that x has remainder 2 when divided by 3. It describes infinitely many integers: …, −4, −1, 2, 5, 8, 11, and so on. Each condition is an arithmetic sequence, and solving a system means finding the integers that belong to every sequence at once.
For example, x ≡ 2 (mod 3), x ≡ 3 (mod 4), and x ≡ 2 (mod 5) asks for a number that is two past a multiple of 3, one less than a multiple of 4, and two past a multiple of 5. The moduli 3, 4, and 5 are pairwise coprime, so the theorem guarantees exactly one answer modulo 3 · 4 · 5 = 60.

Worked example: solve three congruences
Find every integer x satisfying x ≡ 2 (mod 3), x ≡ 3 (mod 4), and x ≡ 2 (mod 5). We will use the constructive form of the theorem, which makes each congruence contribute one term to the answer.
- 1Multiply the moduli.
The full repeat period is M = 3 · 4 · 5 = 60. We will find the answer between 0 and 59, then describe all solutions by adding multiples of 60.
- 2Leave out each modulus in turn.
For each congruence, divide 60 by its modulus. These partial products are divisible by every other modulus, so their contribution vanishes in those other congruences.
- 3Find the modular inverse for each partial product.
Choose yᵢ so that Mᵢyᵢ leaves remainder 1 modulo mᵢ. The products 20 · 2, 15 · 3, and 12 · 3 each leave remainder 1 modulo their corresponding modulus.
- 4Weight each inverse by its target remainder.
Multiply the target remainders 2, 3, and 2 by their corresponding partial product and inverse, then add the three contributions.
- 5Reduce the result to one period.
287 = 4 · 60 + 47, so the least nonnegative answer is 47. Check directly: 47 = 15 · 3 + 2, 47 = 11 · 4 + 3, and 47 = 9 · 5 + 2.
It is often quicker to solve a small system by listing remainders or substituting one condition into another. The formula is especially useful when there are many moduli or the numbers are large; it turns the existence theorem into an explicit recipe.
The constructive formula
For pairwise coprime moduli, define M as their product and Mᵢ = M/mᵢ. Because mᵢ shares no factor with the other moduli, Mᵢ is relatively prime to mᵢ and therefore has a multiplicative inverse yᵢ modulo mᵢ. Set eᵢ = Mᵢyᵢ. Then eᵢ is congruent to 1 modulo mᵢ, while it is congruent to 0 modulo every other modulus.
The sum x = Σaᵢeᵢ therefore has the requested remainder aᵢ modulo mᵢ: every term except the ith one disappears, and that remaining term is aᵢ · 1. This proves existence. It also explains why the formula works rather than merely providing a shortcut.
Why the solution is unique modulo the product
Suppose x and z both satisfy every congruence. For each i, x ≡ aᵢ ≡ z (mod mᵢ), so mᵢ divides x − z. Since the moduli are pairwise coprime, their product M also divides x − z. Thus x ≡ z (mod M): any two solutions differ by a multiple of the product.
The construction above gives at least one solution, and this argument shows all solutions lie in the same residue class. Together, existence and uniqueness prove the theorem. “Unique modulo M” does not mean there is only one integer answer. It means there is one class of answers, such as 47, 107, 167, and 227, all separated by 60.
A second example with larger moduli
Solve x ≡ 1 (mod 4), x ≡ 2 (mod 5), and x ≡ 3 (mod 7). The moduli are pairwise coprime, and their product is 140. Check candidates in the first congruence: 1, 5, 9, 13, 17, … . The value 17 leaves remainder 2 on division by 5 and remainder 3 on division by 7.
For a formula check, M₁ = 35 has inverse 3 modulo 4; M₂ = 28 has inverse 2 modulo 5; and M₃ = 20 has inverse 6 modulo 7. The weighted sum is 1 · 35 · 3 + 2 · 28 · 2 + 3 · 20 · 6 = 105 + 112 + 360 = 577. Reducing 577 modulo 140 gives 17, the same answer found by checking candidates.
Keeping the arithmetic grouped makes the construction easier to audit. A quick final substitution into all three original congruences is still good practice.
What changes when moduli are not coprime?
The pairwise-coprime condition guarantees a solution for any remainders. If two moduli share a common factor, their remainders must agree modulo that shared factor. For two congruences x ≡ a (mod m) and x ≡ b (mod n), a solution exists exactly when gcd(m,n) divides a − b. If a solution exists, it is unique modulo lcm(m,n), not necessarily modulo mn.
Compatible example
Consider x ≡ 2 (mod 6) and x ≡ 5 (mod 9). The greatest common divisor is 3, and 2 ≡ 5 (mod 3), so the conditions are compatible. The number 14 works, and the solutions repeat every lcm(6,9) = 18.
Incompatible example
Now compare x ≡ 1 (mod 6) with x ≡ 2 (mod 9). Both moduli are divisible by 3, but the requested remainders differ modulo 3. One condition requires x ≡ 1 (mod 3), while the other requires x ≡ 2 (mod 3), so no integer can satisfy both.
For many non-coprime congruences, check compatibility for every pair. A generalized Chinese Remainder Theorem then combines compatible conditions, with the final period given by the least common multiple of the moduli.
An intuition: intersecting repeating schedules
Imagine three activities that repeat every 3, 4, and 5 days. One activity can happen only on days numbered 2 modulo 3, another on days numbered 3 modulo 4, and the third on days numbered 2 modulo 5. A day when all three occur must be in the intersection of those schedules. The diagram shows that day 47 is the shared event in the first 60-day cycle.
Because the periods are coprime, the complete pattern resets after 3 · 4 · 5 = 60 days. The next shared day is 107, then 167. The theorem turns this visual search into a general statement: every allowed set of residues has one meeting point in a full product-length cycle.
This scheduling analogy is useful, but the theorem itself is about integers and congruence classes. The moduli need not represent actual time units. They can describe positions, cycles, checksums, or the output of separate modular computations.
Where the Chinese Remainder Theorem is used
Calendar and cycle problems
Combine weekday-like or repeating schedules by finding when their cycles align. The least common multiple gives the repeating interval.
Large integer computation
Some algorithms calculate separately modulo several smaller coprime numbers, then reconstruct the result modulo their product. This can make exact arithmetic more efficient.
Cryptography
Implementations of RSA may use the theorem to perform exponentiation separately modulo prime factors and combine the results. Correct parameters and secure implementation remain essential.
Residue number systems
A large integer can be represented by its remainders across several moduli. When the moduli are coprime, the combined residues identify one number in the product range.
The theorem also appears in abstract algebra as a relationship between arithmetic modulo a product and arithmetic modulo its coprime factors. It explains why computations can sometimes be split into independent modular components and then reassembled without losing information.
Why it is called the Chinese Remainder Theorem
The theorem is associated with a remainder problem recorded in the ancient Chinese mathematical text known as the Sunzi Suanjing. A classic version asks for a number with specified remainders when divided by 3, 5, and 7. One answer is 23 because 23 leaves remainders 2, 3, and 2, respectively; all answers differ by 105. The surviving problem is an early example of the same idea, though the modern theorem and its general proof developed through later mathematical work.
The name refers to this historical source problem, not to a claim that one person alone invented every modern formulation. The reusable construction using products and modular inverses is a systematic way to solve much larger systems.
Common mistakes to avoid
- Assuming the answer is one integer. The theorem gives one residue class; list solutions as x₀ + kM for any integer k.
- Multiplying moduli that are not coprime. Pairwise coprimality is what makes the product the period. For compatible non-coprime systems, use the least common multiple.
- Skipping the compatibility check. Shared factors force the corresponding remainders to agree modulo those factors.
- Using the wrong modular inverse. Verify Mᵢyᵢ ≡ 1 (mod mᵢ) before inserting yᵢ into the formula.
- Forgetting to reduce the final sum. The construction may produce a large number; reduce it modulo M to obtain a convenient representative.
- Confusing congruence with equality. x ≡ 47 (mod 60) means x − 47 is divisible by 60, not that x must equal 47.
Frequently asked questions
What does the Chinese Remainder Theorem say?
If the moduli are pairwise coprime, any chosen remainders determine exactly one solution modulo the product of the moduli.
How do I find a solution quickly?
For small moduli, list the numbers that satisfy one condition and test them against the others. For larger systems, use partial products and modular inverses.
Why is the solution unique only modulo the product?
Adding the product leaves every remainder unchanged. The uniqueness proof shows any two solutions differ by a multiple of that product.
Can the theorem solve congruences with non-coprime moduli?
A generalized form can. The remainders must agree modulo every shared factor; when compatible, the result is unique modulo the least common multiple.
What if the remainders conflict?
Then no integer satisfies all conditions. For example, x ≡ 1 (mod 6) and x ≡ 2 (mod 9) conflict modulo 3.
What is the difference between a solution and all solutions?
A least nonnegative solution x₀ is one representative. All integer solutions are x = x₀ + kM, where k is any integer and M is the product for pairwise coprime moduli.
Reference: Stanford notes on the Chinese Remainder Theorem.