DISCRETE MATH • NUMBER THEORY AND CRYPTOGRAPHY

Chinese remainder theorem (intro)

A classical result that reconstructs an integer from its remainders modulo pairwise coprime moduli.

Historical Context & Motivation

The Chinese Remainder Theorem (CRT) is one of the oldest results in number theory, originating in the mathematical traditions of ancient China. The core problem it addresses is deceptively simple: given several remainders of an unknown integer with respect to different divisors, can we reconstruct the original integer—or at least determine it modulo the product of those divisors? This question arises naturally in counting, calendrical computation, and modular arithmetic, and the CRT provides an elegant affirmative answer whenever the divisors are pairwise coprime. The theorem has remained central to mathematics for nearly two millennia because it transforms a system of congruences into a single congruence, enabling powerful decomposition techniques used throughout algebra, computer science, and cryptography.

~3rd century
Sunzi Suanjing
The Chinese mathematician Sun Tzu (Sunzi) poses the famous problem: 'There are certain things whose number is unknown. When divided by 3, the remainder is 2; by 5, the remainder is 3; and by 7, the remainder is 2. What is the number?' His solution, described in the Sunzi Suanjing, is the earliest known instance of the CRT.
1247
Qin Jiushao's General Algorithm
The Song Dynasty mathematician Qin Jiushao published the Shushu Jiuzhang (Mathematical Treatise in Nine Sections), which contains a systematic algorithm—the Dayan qiuyi shu—for solving systems of linear congruences, effectively generalizing the CRT to arbitrary pairwise coprime moduli.
1801
Gauss's Disquisitiones Arithmeticae
Carl Friedrich Gauss independently formulated and proved the CRT in the Western mathematical tradition. His treatment in Disquisitiones Arithmeticae placed the result on rigorous algebraic footing and connected it to the structure of ℤ/nℤ.
1977
RSA Cryptosystem
Rivest, Shamir, and Adleman published the RSA algorithm, in which the CRT is used to speed up decryption by decomposing modular exponentiation modulo n = pq into two independent exponentiations modulo p and q. This application cemented the CRT's importance in modern cryptography.

From Sunzi's ancient puzzle to RSA's secure communications, the underlying question has remained the same: how can we efficiently recover an integer from partial information encoded as residues? The CRT answers this question with a constructive proof that yields both an existence guarantee and an explicit algorithm. In this lesson, we develop the theorem from its formal statement through a complete constructive method and illustrate it with worked examples and practice problems.

Core Principles & Definitions

Before stating the CRT, we need to establish several foundational concepts from modular arithmetic. The theorem rests on the interplay between divisibility, coprimality, and the structure of congruence classes. Understanding these building blocks will make the theorem's statement feel almost inevitable.

1

Congruence Modulo m

We write a ≡ r (mod m) to mean that m divides (a − r). Equivalently, a and r leave the same remainder when divided by m. The set of all integers congruent to r modulo m forms a residue class.
2

Pairwise Coprimality

Integers m₁, m₂, …, mₖ are pairwise coprime if gcd(mᵢ, mⱼ) = 1 for every pair i ≠ j. This condition is strictly stronger than requiring gcd of all moduli simultaneously to be 1 (e.g., 6 and 10 share the factor 2, so they are not coprime).
3

System of Congruences

A system of simultaneous congruences is a collection of equations x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), …, x ≡ aₖ (mod mₖ). The CRT tells us when and how a unique solution modulo M = m₁ × m₂ × … × mₖ exists.
4

Modular Inverse

Given integers a and m with gcd(a, m) = 1, the modular inverse of a modulo m is an integer a⁻¹ such that a × a⁻¹ ≡ 1 (mod m). Existence is guaranteed by Bézout's identity and can be computed via the extended Euclidean algorithm.
5

Ring Isomorphism (Preview)

Algebraically, the CRT establishes an isomorphism ℤ/Mℤ ≅ ℤ/m₁ℤ × ℤ/m₂ℤ × … × ℤ/mₖℤ when the mᵢ are pairwise coprime. This decomposition is the algebraic heart of the theorem.
KEY TAKEAWAY
Think of the CRT like a combination lock with independent dials. If you know the position of each dial (the remainders), and the dials don't interfere with each other (pairwise coprimality), you can reconstruct the full combination (the integer modulo M) uniquely. The condition gcd(mᵢ, mⱼ) = 1 ensures the dials are truly independent—overlap in factors would create ambiguity, just as two linked gears would prevent you from setting them independently.

Visual Explanation

A powerful way to visualize the CRT is to arrange the integers 0 through M − 1 in a grid and observe how each integer maps to its tuple of remainders. The following diagram illustrates the case M = 3 × 5 = 15, showing how every integer in {0, 1, …, 14} corresponds to a unique pair (r₃, r₅) where r₃ ∈ {0, 1, 2} and r₅ ∈ {0, 1, 2, 3, 4}. The CRT guarantees that this mapping is a bijection—every cell in the 3 × 5 grid is filled by exactly one integer.

The 3 × 5 grid displays every integer from 0 to 14 at its position (x mod 3, x mod 5). The highlighted cell at (1, 1) contains x = 1. Notice that no cell is empty and no integer appears twice—this is the bijective correspondence guaranteed by the CRT when gcd(3, 5) = 1.

Observe the diagonal pattern in which consecutive integers traverse the grid. Starting from 0 in the upper-left corner, each step right and one row down (wrapping around) places the next integer. This wrapping behavior reflects the fact that incrementing x by 1 increases x mod 3 by 1 (mod 3) and x mod 5 by 1 (mod 5) simultaneously. The pairwise coprimality of 3 and 5 ensures the path visits every cell before returning to the start after exactly 15 steps, producing the bijection. If the moduli shared a common factor—say 4 and 6—some cells would be unreachable and the mapping would fail to be surjective.

Mathematical Framework

We now state the Chinese Remainder Theorem precisely and develop its constructive proof. The construction not only proves existence and uniqueness but also provides an explicit formula for computing the solution.

SYSTEM OF CONGRUENCES
x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), …, x ≡ aₖ (mod mₖ)
Given: m₁, m₂, …, mₖ are pairwise coprime positive integers and a₁, a₂, …, aₖ are arbitrary integers. Claim: there exists a unique solution x modulo M = m₁ × m₂ × … × mₖ.

Constructive Proof Outline

For each i from 1 to k, define Mᵢ = M / mᵢ, which is the product of all moduli except mᵢ. Because the moduli are pairwise coprime, gcd(Mᵢ, mᵢ) = 1, and therefore Mᵢ has a multiplicative inverse modulo mᵢ. Let yᵢ denote this inverse, so Mᵢ × yᵢ ≡ 1 (mod mᵢ). The solution is then constructed as a weighted sum.

CRT SOLUTION FORMULA
x ≡ Σᵢ₌₁ᵏ aᵢ × Mᵢ × yᵢ (mod M)
where Mᵢ = M / mᵢ and yᵢ = Mᵢ⁻¹ (mod mᵢ). Each term aᵢ × Mᵢ × yᵢ contributes aᵢ modulo mᵢ and vanishes modulo every other mⱼ (j ≠ i), because mⱼ divides Mᵢ.

To verify correctness, consider the i-th congruence. Reducing the sum modulo mᵢ, every term with j ≠ i contributes 0 because mᵢ divides Mⱼ. The i-th term reduces to aᵢ × Mᵢ × yᵢ ≡ aᵢ × 1 ≡ aᵢ (mod mᵢ). For uniqueness, suppose x and x' both satisfy the system. Then mᵢ divides (x − x') for every i, and since the mᵢ are pairwise coprime, their product M also divides (x − x'), so x ≡ x' (mod M).

MODULAR INVERSE VIA EXTENDED EUCLIDEAN ALGORITHM
gcd(Mᵢ, mᵢ) = 1 ⟹ ∃ yᵢ, tᵢ ∈ ℤ : Mᵢ × yᵢ + mᵢ × tᵢ = 1
By Bézout's identity, the extended Euclidean algorithm produces yᵢ and tᵢ. Reducing modulo mᵢ gives Mᵢ × yᵢ ≡ 1 (mod mᵢ), confirming yᵢ is the required modular inverse.
⚠️ Why Pairwise Coprimality?
If gcd(mᵢ, mⱼ) = d > 1 for some pair, the system x ≡ 0 (mod mᵢ), x ≡ 1 (mod mⱼ) has no solution whenever d does not divide 1 (which it never does for d > 1). The pairwise coprime condition is therefore not merely technical—it is necessary for the theorem to guarantee existence for all choices of remainders aᵢ.

Step-by-Step Algorithm & Diagram

The construction in the proof translates directly into a systematic algorithm. The following diagram outlines the computational pipeline for solving a system of k congruences. Each stage is independent and parallelizable—an observation that underlies the CRT's utility in computer arithmetic, where large computations modulo M are broken into smaller ones modulo each mᵢ.

The CRT algorithm pipeline: compute the total modulus M, the partial products Mᵢ, their modular inverses yᵢ, and then assemble the solution as a weighted sum. The verification step confirms each congruence is satisfied.
Key quantities in the CRT construction
QuantityDefinitionRole in Algorithm
Mm₁ × m₂ × … × mₖThe modulus of the unique solution; defines the solution space.
MᵢM / mᵢPartial product; divisible by every mⱼ (j ≠ i) but coprime to mᵢ.
yᵢMᵢ⁻¹ (mod mᵢ)Modular inverse; ensures the i-th term contributes aᵢ modulo mᵢ.
eᵢ = Mᵢ × yᵢOrthogonal idempotentSatisfies eᵢ ≡ 1 (mod mᵢ) and eᵢ ≡ 0 (mod mⱼ) for j ≠ i.

Worked Example

We now apply the CRT algorithm to solve Sunzi's classic problem: find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5), and x ≡ 2 (mod 7). Since gcd(3, 5) = gcd(3, 7) = gcd(5, 7) = 1, the moduli are pairwise coprime and the CRT applies.

Sunzi's Problem: x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7)
1
Step 1 — Compute MThe total modulus is M = 3 × 5 × 7 = 105.
M = 105
2
Step 2 — Compute Partial Products MᵢM₁ = 105 / 3 = 35, M₂ = 105 / 5 = 21, M₃ = 105 / 7 = 15.
M₁ = 35, M₂ = 21, M₃ = 15
3
Step 3 — Find Modular Inverses yᵢWe need y₁ such that 35 × y₁ ≡ 1 (mod 3). Since 35 ≡ 2 (mod 3) and 2 × 2 = 4 ≡ 1 (mod 3), we get y₁ = 2. Next, y₂ such that 21 × y₂ ≡ 1 (mod 5). Since 21 ≡ 1 (mod 5), we get y₂ = 1. Finally, y₃ such that 15 × y₃ ≡ 1 (mod 7). Since 15 ≡ 1 (mod 7), we get y₃ = 1.
y₁ = 2, y₂ = 1, y₃ = 1
4
Step 4 — Assemble the Solutionx = a₁ × M₁ × y₁ + a₂ × M₂ × y₂ + a₃ × M₃ × y₃ = 2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1 = 140 + 63 + 30 = 233.
x = 233 (before reduction)
5
Step 5 — Reduce Modulo M and Verifyx ≡ 233 (mod 105). Since 233 = 2 × 105 + 23, we get x = 23. Verification: 23 mod 3 = 2 ✓, 23 mod 5 = 3 ✓, 23 mod 7 = 2 ✓. The unique solution modulo 105 is x = 23, and the general solution is x = 23 + 105t for any integer t.
x ≡ 23 (mod 105)
💡 Interpretation
The answer x = 23 is the smallest positive integer satisfying all three congruences. Historically, Sunzi stated the answer as 23, matching our result. Notice how each orthogonal idempotent eᵢ = Mᵢ × yᵢ acts as a 'selector': e₁ = 70, e₂ = 21, e₃ = 15, and indeed 70 ≡ 1 (mod 3), 70 ≡ 0 (mod 5), 70 ≡ 0 (mod 7), confirming the orthogonality property.

Strengths, Limitations & Comparisons

The CRT is remarkably powerful in its domain of applicability, but it is essential to understand its precise scope and the situations where alternative methods are needed. The following table summarizes the key strengths and limitations of the introductory form of the CRT.

Strengths and limitations of the CRT (introductory form)
AspectStrengthsLimitations
Existence & UniquenessGuarantees a unique solution mod M for any choice of remainders aᵢ, provided moduli are pairwise coprime.Fails entirely if any pair of moduli shares a common factor > 1, unless extra compatibility conditions on the remainders are met.
Constructive MethodThe proof provides an explicit formula and algorithm, not just an existence claim. Easily programmable.Requires computation of modular inverses via extended Euclidean algorithm; not 'by inspection' for large moduli.
Computational EfficiencyDecomposes large modular computations into smaller independent ones—critical for RSA decryption speedup (~4× faster).The final assembly step involves products and sums of potentially large integers, though this is manageable with modular reduction.
GeneralityExtends naturally to polynomial rings, abstract algebra, and multi-dimensional settings via the ring-theoretic formulation.The introductory form covers only ℤ; general versions require familiarity with ideals and ring homomorphisms.
KEY TAKEAWAY
In signal processing, a complex signal is decomposed into independent frequency components via the Fourier transform, manipulated in the frequency domain, and then reconstructed. The CRT works analogously for integers: decompose x into its residues modulo independent (coprime) moduli, perform arithmetic in each small modular domain, and reconstruct via the CRT formula. The pairwise coprime condition is the analog of having orthogonal frequency components—without it, the decomposition becomes degenerate.

Connection to Advanced Theory

The introductory CRT for integers is the gateway to a rich family of results in abstract algebra and applied mathematics. The algebraic generalization recasts the theorem as a ring isomorphism and extends it to polynomial rings, enabling powerful applications in coding theory and algebraic geometry. Understanding where the introductory version sits within this hierarchy helps contextualize both its power and its boundaries.

Introductory CRT vs. General (Ring-Theoretic) CRT
FeatureIntroductory CRT (This Lesson)General CRT (Abstract Algebra)
DomainIntegers ℤ with moduli m₁, …, mₖAny commutative ring R with ideals I₁, …, Iₖ
Coprimality Conditiongcd(mᵢ, mⱼ) = 1 for all i ≠ jIᵢ + Iⱼ = R (ideals are comaximal) for all i ≠ j
Statementℤ/Mℤ ≅ ℤ/m₁ℤ × … × ℤ/mₖℤR/(I₁ ∩ … ∩ Iₖ) ≅ R/I₁ × … × R/Iₖ
Key ApplicationRSA speedup, modular arithmetic, hash functionsPolynomial interpolation, error-correcting codes (Reed–Solomon), algebraic number theory
PrerequisitesModular arithmetic, gcd, extended Euclidean algorithmRing theory, ideal arithmetic, homomorphism theorems

In a course on number theory and cryptography, you will encounter the CRT in several critical contexts. In RSA decryption, the CRT reduces exponentiation modulo n = p × q to two independent exponentiations modulo p and modulo q, yielding a roughly fourfold speedup. In secret sharing (e.g., Asmuth–Bloom scheme), the CRT enables threshold reconstruction of a secret from shares. In residue number systems, integers are represented as tuples of residues, allowing carry-free addition and multiplication—a technique used in high-performance digital signal processing hardware. Each of these applications exploits the CRT's ability to decompose a large problem into independent smaller problems.

Practice Problems

PROBLEM 1CONCEPTUAL
Explain why the system x ≡ 1 (mod 4) and x ≡ 3 (mod 6) cannot be solved using the Chinese Remainder Theorem as stated in this lesson. Does this mean the system has no solution at all? Justify your answer.
PROBLEM 2BASIC CALCULATION
Use the CRT to solve the system: x ≡ 1 (mod 3), x ≡ 2 (mod 5). Express your answer as x ≡ ? (mod 15).
PROBLEM 3INTERMEDIATE
Solve the system: x ≡ 3 (mod 4), x ≡ 1 (mod 5), x ≡ 6 (mod 7). Show all steps of the CRT construction including the computation of each modular inverse.
PROBLEM 4APPLIED
A computer system stores a secret integer S (0 ≤ S < 385) by recording three residues: S mod 5 = 4, S mod 7 = 3, S mod 11 = 9. Use the CRT to recover S. Verify that 5, 7, and 11 are pairwise coprime.
PROBLEM 5CRITICAL THINKING
Prove that the orthogonal idempotents e₁, e₂, …, eₖ (where eᵢ = Mᵢ × yᵢ) satisfy: (a) eᵢ ≡ δᵢⱼ (mod mⱼ), where δᵢⱼ is the Kronecker delta, and (b) e₁ + e₂ + … + eₖ ≡ 1 (mod M). Explain why property (b) follows from property (a) and the CRT itself.

Summary

The Chinese Remainder Theorem provides a constructive method for solving systems of simultaneous congruences when the moduli m₁, m₂, …, mₖ are pairwise coprime. The theorem guarantees that the system x ≡ aᵢ (mod mᵢ) has a unique solution modulo M = m₁ × m₂ × … × mₖ, and the solution is computed using partial products Mᵢ and their modular inverses yᵢ via the formula x ≡ Σ aᵢ × Mᵢ × yᵢ (mod M).

Algebraically, the CRT establishes an isomorphism ℤ/Mℤ ≅ ℤ/m₁ℤ × … × ℤ/mₖℤ, decomposing a large ring into a direct product of smaller ones. This decomposition underlies applications in RSA cryptography (speedup of modular exponentiation), residue number systems (parallel arithmetic), and secret sharing (threshold reconstruction). The key prerequisite is pairwise coprimality—without it, the bijection breaks down and solutions may not exist for arbitrary remainders.

Varsity Tutors • Discrete Math • Chinese remainder theorem (intro)