Chinese Remainder Theorem

⚡ Key Takeaways

Chinese Remainder Theorem (CRT): A system of simultaneous congruences with pairwise coprime moduli has a unique solution modulo the product of those moduli. In words: if you know a number's remainders upon division by several coprime numbers, you can reconstruct the number uniquely (up to the product). It applies in number theory, abstract algebra, cryptography, and computer arithmetic. Known to the Chinese mathematician Sun Tzu (c. 3rd–5th century CE) and fully formalized by Gauss in 1801.

💡 The Core Insight

Coprime moduli carry independent information. Knowing x  n1x \bmod n_1 tells you nothing about x  n2x \bmod n_2 when gcd⁡(n1,n2)=1\gcd(n_1,n_2)=1, so the remainders can be chosen freely and combined uniquely. The "gluing" of these independent pieces into one number is exactly a ring isomorphism, and it works precisely because coprimality lets you build "indicator" elements that are 11 in one component and 00 in the others.

Formal Statement

DefinitionSystem of Congruences

Let n1,n2,…,nkn_1, n_2, \dots, n_k be positive integers and a1,a2,…,aka_1, a_2, \dots, a_k be integers. A system of simultaneous congruences is

1
x≡a1(modn1),x≡a2(modn2),…,x≡ak(modnk).\quad x \equiv a_1 \pmod{n_1}, \quad x \equiv a_2 \pmod{n_2}, \quad \dots, \quad x \equiv a_k \pmod{n_k}.

Derivation hint: This is simply a list of independent divisibility constraints ni∣(x−ai)n_i \mid (x - a_i). Here xx is the unknown integer, each aia_i is the required residue modulo nin_i, and the moduli nin_i are said to be pairwise coprime if gcd⁡(ni,nj)=1\gcd(n_i, n_j) = 1 for all i≠ji \neq j.

TheoremChinese Remainder Theorem — Classical Form

If the moduli n1,…,nkn_1, \dots, n_k are pairwise coprime and N=∏i=1kniN = \prod_{i=1}^{k} n_i, then the system [1] has a solution xx, and this solution is unique modulo NN. That is, there is exactly one residue class x  Nx \bmod N satisfying all kk congruences. An explicit solution is given by

2
x≡∑i=1kai Ni Mi(modN),Ni=Nni,Mi≡Ni−1(modni).\quad x \equiv \sum_{i=1}^{k} a_i\, N_i\, M_i \pmod{N}, \qquad N_i = \frac{N}{n_i}, \qquad M_i \equiv N_i^{-1} \pmod{n_i}.

Derivation hint: NiN_i is divisible by every njn_j with j≠ij\neq i, so the ii-th term acts as a "selector" that is aia_i mod nin_i and 00 mod the others.

TheoremChinese Remainder Theorem — Ring-Theoretic Form

If n1,…,nkn_1, \dots, n_k are pairwise coprime with product NN, the natural reduction map is a ring isomorphism:

3
Z/NZ  ≅  Z/n1Z×Z/n2Z×⋯×Z/nkZ,x  N⟼(x  n1,…,x  nk).\quad \mathbb{Z}/N\mathbb{Z} \;\cong\; \mathbb{Z}/n_1\mathbb{Z} \times \mathbb{Z}/n_2\mathbb{Z} \times \cdots \times \mathbb{Z}/n_k\mathbb{Z}, \qquad x \bmod N \longmapsto (x \bmod n_1, \dots, x \bmod n_k).

Derivation hint: The map is well-defined and injective because pairwise coprimality forces N∣(x−y)N \mid (x-y) from ni∣(x−y)n_i \mid (x-y) for all ii; surjectivity follows by counting, since both sides have NN elements. Restricting to units gives the multiplicative version, useful for Euler's Totient Function:

4
(Z/NZ)×  ≅  (Z/n1Z)××⋯×(Z/nkZ)×,φ(N)=∏i=1kφ(ni).\quad (\mathbb{Z}/N\mathbb{Z})^\times \;\cong\; (\mathbb{Z}/n_1\mathbb{Z})^\times \times \cdots \times (\mathbb{Z}/n_k\mathbb{Z})^\times, \qquad \varphi(N) = \prod_{i=1}^k \varphi(n_i).

Derivation hint: An element is a unit iff it is a unit in each component; multiplicativity of φ\varphi then follows from the cardinality of the right-hand product.

Why It Holds / Derivation

ProofExistence and Uniqueness (Classical)

Step 1 — Build the selectors. For each ii, set Ni=N/ni=∏j≠injN_i = N/n_i = \prod_{j \neq i} n_j. Since the njn_j are pairwise coprime, NiN_i is coprime to nin_i (no njn_j with j≠ij \neq i shares a factor with nin_i). Therefore NiN_i is invertible modulo nin_i, and there exists MiM_i with

5
NiMi≡1(modni).\quad N_i M_i \equiv 1 \pmod{n_i}.

Derivation hint: gcd⁡(Ni,ni)=1\gcd(N_i, n_i)=1 guarantees an inverse by <a class="wiki-link" href="/wiki/math-numthy-bezout-identity">Bézout&#39;s Identity</a>; compute MiM_i via the <span class="wiki-link-missing">Extended Euclidean Algorithm</span>.

Step 2 — Verify the candidate. Define x=∑i=1kaiNiMix = \sum_{i=1}^k a_i N_i M_i. Fix an index rr. For i≠ri \neq r, the term aiNiMia_i N_i M_i contains the factor nrn_r (since nr∣Nin_r \mid N_i), so it vanishes mod nrn_r. For i=ri = r,

6
arNrMr≡ar⋅1=ar(modnr).\quad a_r N_r M_r \equiv a_r \cdot 1 = a_r \pmod{n_r}.

Derivation hint: Use [5] with i=ri=r to replace NrMrN_r M_r by 11 modulo nrn_r. Hence x≡ar(modnr)x \equiv a_r \pmod{n_r} for every rr, so xx solves the system.

Step 3 — Uniqueness. Suppose xx and yy both solve [1]. Then ni∣(x−y)n_i \mid (x - y) for all ii. Because the nin_i are pairwise coprime, their product divides the difference:

7
ni∣(x−y) ∀i  ⟹  N=lcm⁡(n1,…,nk)∣(x−y).\quad n_i \mid (x-y)\ \forall i \;\Longrightarrow\; N = \operatorname{lcm}(n_1,\dots,n_k) \mid (x-y).

Derivation hint: For pairwise coprime moduli, lcm⁡=∏ni=N\operatorname{lcm} = \prod n_i = N; a number divisible by each coprime factor is divisible by their product. Thus x≡y(modN)x \equiv y \pmod{N}, proving uniqueness modulo NN. ■\blacksquare

∎
⚠️ Pairwise vs. Mutually Coprime

Step 3 requires pairwise coprimality, not merely that gcd⁡(n1,…,nk)=1\gcd(n_1,\dots,n_k)=1 collectively. The moduli 6,10,156, 10, 15 satisfy gcd⁡(6,10,15)=1\gcd(6,10,15)=1 but are not pairwise coprime, and CRT in its clean form fails for them.

mathematician · Carl Friedrich Gauss | 1777–1855

While the problem dates to ancient China, it was Gauss who gave the theorem its rigorous modern treatment in his 1801 masterwork Disquisitiones Arithmeticae. Gauss introduced the congruence notation ≡\equiv still used today and systematically developed the theory of residues, placing the Chinese Remainder Theorem within a coherent algebraic framework. His viewpoint anticipated the ring-isomorphism formulation that abstract algebra would later make precise, and his constructive method for combining congruences is essentially the selector argument given above.

Building Intuition

🧠 Intuition

Think of an odometer with several independent dials, each cycling at a different coprime period — one resets every 33 clicks, one every 55, one every 77. Because the periods share no common factor, the dials only realign after 3×5×7=1053 \times 5 \times 7 = 105 clicks. During those 105105 steps, every combination of dial positions occurs exactly once. So specifying where each dial points pins down the click count uniquely within one full cycle. The CRT says reading the dials (the remainders) and reading the odometer (the number mod 105105) are two equivalent languages for the same information — and pairwise coprimality is precisely what makes the dials independent.

Figure
CRT as independent cycling clocks: residues mod 3 and mod 5 align uniquely every 15 steps

```svg

x ≡ 2 (mod 3), x ≡ 3 (mod 5) → x ≡ 8 (mod 15) mod 3 0 1 2 mod 5 0 1 2 3 4 unique alignment at x = 8 within one cycle of length 15

```

Worked Examples

ExampleSun Tzu's Classic Problem

Given: Find the smallest positive xx with

x≡2(mod3),x≡3(mod5),x≡2(mod7).x \equiv 2 \pmod 3, \quad x \equiv 3 \pmod 5, \quad x \equiv 2 \pmod 7.

Step 1 — Product and selectors. N=3⋅5⋅7=105N = 3\cdot 5\cdot 7 = 105. N1=105/3=35N_1 = 105/3 = 35, N2=105/5=21N_2 = 105/5 = 21, N3=105/7=15N_3 = 105/7 = 15.

Step 2 — Inverses (the MiM_i). 35≡2(mod3)35 \equiv 2 \pmod 3, need 2M1≡1(mod3)⇒M1=22 M_1 \equiv 1 \pmod 3 \Rightarrow M_1 = 2. 21≡1(mod5)⇒M2=121 \equiv 1 \pmod 5 \Rightarrow M_2 = 1. 15≡1(mod7)⇒M3=115 \equiv 1 \pmod 7 \Rightarrow M_3 = 1.

Step 3 — Combine via [2].

x≡2⋅35⋅2+3⋅21⋅1+2⋅15⋅1=140+63+30=233(mod105).x \equiv 2\cdot 35\cdot 2 + 3\cdot 21\cdot 1 + 2\cdot 15\cdot 1 = 140 + 63 + 30 = 233 \pmod{105}.

Step 4 — Reduce. 233−2⋅105=23233 - 2\cdot 105 = 23.

Answer: x≡23(mod105)\boxed{x \equiv 23 \pmod{105}} (check: 23=7⋅3+223 = 7\cdot3+2, 23=4⋅5+323=4\cdot5+3, 23=3⋅7+223=3\cdot7+2 ✓).

ExampleTwo-Congruence Sequential Substitution

Given: Solve x≡4(mod9)x \equiv 4 \pmod 9 and x≡7(mod11)x \equiv 7 \pmod{11}.

Step 1 — Parametrize the first. x=4+9tx = 4 + 9t for integer tt.

Step 2 — Substitute into the second. 4+9t≡7(mod11)⇒9t≡3(mod11).4 + 9t \equiv 7 \pmod{11} \Rightarrow 9t \equiv 3 \pmod{11}.

Step 3 — Invert 99 mod 1111. Since 9⋅5=45≡1(mod11)9 \cdot 5 = 45 \equiv 1 \pmod{11}, multiply: t≡5⋅3=15≡4(mod11)t \equiv 5\cdot 3 = 15 \equiv 4 \pmod{11}.

Step 4 — Back-substitute. t=4+11st = 4 + 11s, so x=4+9(4+11s)=40+99sx = 4 + 9(4 + 11s) = 40 + 99s.

Answer: x≡40(mod99)\boxed{x \equiv 40 \pmod{99}} (check: 40=4⋅9+440 = 4\cdot9+4, 40=3⋅11+740=3\cdot11+7 ✓). Note N=9⋅11=99N = 9\cdot 11 = 99.

Common Misconceptions

⚠️ CRT Does Not Require Prime Moduli

A frequent error is to assume the moduli must be primes. They need only be pairwise coprime. For instance 8,9,258, 9, 25 are pairwise coprime (and composite), and CRT applies perfectly with N=1800N = 1800. Conversely, primality alone is not the issue — repeated primes like 4,84, 8 break coprimality.

CounterexampleNon-Coprime Moduli Can Have No Solution

Consider

x≡1(mod4),x≡2(mod6).x \equiv 1 \pmod 4, \qquad x \equiv 2 \pmod 6.

Here gcd⁡(4,6)=2≠1\gcd(4,6) = 2 \neq 1. The first congruence forces xx odd; the second forces xx even (since x≡2(mod6)x \equiv 2 \pmod 6 means xx is even). These contradict, so no solution exists. A solution exists for non-coprime moduli only if the congruences agree on common factors: ai≡aj(modgcd⁡(ni,nj))a_i \equiv a_j \pmod{\gcd(n_i,n_j)}. When they do agree, the solution is unique modulo lcm⁡(n1,…,nk)\operatorname{lcm}(n_1,\dots,n_k), not the product.

Connections

connection

CRT sits at a crossroads of algebra and number theory. Its unit-group form [4] gives the multiplicativity of <a class="wiki-link" href="/wiki/eulers-totient-function">Euler&#39;s Totient Function</a>, φ(mn)=φ(m)φ(n)\varphi(mn)=\varphi(m)\varphi(n) for coprime m,nm,n. The constructive solution leans on the Extended Euclidean Algorithm and Bézout's Identity to compute inverses. The ring isomorphism [3] is the prototype of decomposing a Quotient Ring into a product, and it generalizes to comaximal ideals in any commutative ring — the same statement holds for R/(I1∩⋯∩Ik)R/(I_1 \cap \cdots \cap I_k) when the ideals are pairwise comaximal. In the structure theory of finite abelian groups, CRT is what lets Z/NZ\mathbb{Z}/N\mathbb{Z} split into its primary components Z/peZ\mathbb{Z}/p^e\mathbb{Z}. It also underlies Fermat's Little Theorem applications when assembling results across prime factors.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- c. 3rd–5th century CE: The Chinese mathematician Sun Tzu poses the "counting in threes, fives, sevens" problem in Sunzi Suanjing, the earliest known statement.
- c. 7th century: Indian mathematician Brahmagupta develops the kuttaka method for linear indeterminate equations, closely related to CRT computations.
- 1247: Qin Jiushao publishes the Mathematical Treatise in Nine Sections, giving the first complete general algorithm (Dayan method) for the case of non-coprime moduli.
- 1500s–1600s: European mathematicians, including Fibonacci earlier and later commentators, treat scattered instances of remainder problems.
- 1734: Leonhard Euler works on systems of congruences in the context of number theory.
- 1801: Carl Friedrich Gauss formalizes the theorem in Disquisitiones Arithmeticae, introducing congruence notation and the modern proof.
- late 1800s: Richard Dedekind and the rise of ideal theory recast CRT abstractly, anticipating the ring-isomorphism form.
- 20th century: Emmy Noether and others generalize CRT to commutative rings with comaximal ideals, making [3] a standard structural theorem.
- 1970s–present: CRT becomes computationally central in cryptography (RSA, 1977) and computer algebra.

Subtleties & Limits

open-problem

While the CRT itself is fully proved, its applications touch open and hard questions. Reconstructing an integer from residues is trivial, but the inverse problem with errors — recovering a number from noisy or partially corrupted residues — leads to the CRT decoding problem, whose hardness underpins certain lattice-based and number-theoretic cryptosystems. In computational number theory, the efficiency of CRT-based algorithms depends on factoring or on knowing the moduli, and questions about the distribution of residues (e.g., how "random" CRT-reconstructed values behave) connect to deep conjectures in analytic number theory. Generalizing CRT to non-commutative rings and to module-theoretic settings is well understood, but the interplay between CRT and the difficulty of integer factorization keeps it at the heart of computational complexity questions.

See Also

Modular Arithmetic · Euler's Totient Function · Extended Euclidean Algorithm · RSA Cryptosystem · Quotient Ring · Fermat's Little Theorem · Structure Theorem for Finite Abelian Groups