01 / 21
3 5 7

Chinese Remainder
Theorem

Discover how to solve systems of modular equations simultaneously: one of the most elegant results in number theory.

Discrete Math

What Is Modular Arithmetic?

Modular arithmetic studies the remainder after division. When we write \( a \equiv r \pmod{m} \), we mean that \( a \) divided by \( m \) leaves remainder \( r \).

\( 17 \equiv 2 \pmod{5} \)
\( 17 = 3 \times 5 + 2 \), so the remainder is 2.
\( 23 \equiv 2 \pmod{3} \)
\( 23 = 7 \times 3 + 2 \), so the remainder is 2.

Systems of Congruences

A system of congruences asks: can we find a single number \( x \) that satisfies multiple remainder conditions at once?

Does such an \( x \) exist? If so, is it unique? The Chinese Remainder Theorem answers both questions.

Visualizing Remainders on a Number Line

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 5 8 11 14 mod 3 3 8 13 mod 5 8 ✓ Both!

The Chinese Remainder Theorem

Existence
A solution always exists when the moduli are pairwise coprime.
Uniqueness
The solution is unique modulo \( M = m_1 m_2 \cdots m_k \).

What Does Pairwise Coprime Mean?

Two integers are coprime (or relatively prime) if their greatest common divisor is \( 1 \). A set of moduli is pairwise coprime when every pair in the set is coprime.

✓ Pairwise coprime
\( \{3, 5, 7\} \): \( \gcd(3,5)=1 \), \( \gcd(3,7)=1 \), \( \gcd(5,7)=1 \).
✕ Not pairwise coprime
\( \{4, 6, 7\} \): \( \gcd(4,6)=2 \neq 1 \), so CRT does not apply directly.

CRT vs. Single Congruence

Single Congruence CRT (System)
Form \( x \equiv a \pmod{m} \) Multiple congruences at once
Solution Space Infinitely many, spaced by \( m \) Unique modulo \( M = \prod m_i \)
Requirement None on \( m \) Moduli must be pairwise coprime
Example \( x \equiv 2 \pmod{5} \) \( x \equiv 2 \pmod{3},\; x \equiv 3 \pmod{5} \)

How to Solve a CRT System

1
Compute \( M \). Multiply all moduli: \( M = m_1 \cdot m_2 \cdots m_k \).
2
Compute each \( M_i \). Set \( M_i = M / m_i \) for each equation.
3
Find each \( y_i \). Find the modular inverse: \( M_i \cdot y_i \equiv 1 \pmod{m_i} \).
4
Combine. The solution is \( x \equiv \displaystyle\sum_{i=1}^{k} a_i \cdot M_i \cdot y_i \pmod{M} \).

Step-by-Step Checklist

1
Verify coprimality. Check \( \gcd(m_i, m_j) = 1 \) for all pairs. If not, CRT does not apply directly.
2
Compute \( M \) and each \( M_i \). This sets up the partial products you need.
3
Find modular inverses. Use the extended Euclidean algorithm or trial: \( M_i y_i \equiv 1 \pmod{m_i} \).
4
Build the solution. Sum \( a_i M_i y_i \) and reduce mod \( M \).
5
Verify. Plug \( x \) back into each original congruence to confirm.

Example 1: Two Congruences

1
\( M = 3 \times 5 = 15 \).
2
\( M_1 = 15/3 = 5 \), \( M_2 = 15/5 = 3 \).
3
Find inverses: \( 5 y_1 \equiv 1 \pmod{3} \Rightarrow y_1 = 2 \). \( 3 y_2 \equiv 1 \pmod{5} \Rightarrow y_2 = 2 \).
4
\( x = 2 \cdot 5 \cdot 2 + 3 \cdot 3 \cdot 2 = 20 + 18 = 38 \equiv \) 8 \( \pmod{15} \).

Example 2: Three Congruences

1
\( M = 2 \times 3 \times 5 = 30 \).
2
\( M_1 = 15 \), \( M_2 = 10 \), \( M_3 = 6 \).
3
Inverses: \( 15 y_1 \equiv 1 \pmod{2} \Rightarrow y_1 = 1 \). \( 10 y_2 \equiv 1 \pmod{3} \Rightarrow y_2 = 1 \). \( 6 y_3 \equiv 1 \pmod{5} \Rightarrow y_3 = 1 \).
4
\( x = 1(15)(1) + 2(10)(1) + 3(6)(1) = 15 + 20 + 18 = 53 \equiv \) 23 \( \pmod{30} \).

Example 3: Larger Moduli

1
\( M = 4 \times 9 \times 7 = 252 \). Moduli are pairwise coprime ✓.
2
\( M_1 = 63 \), \( M_2 = 28 \), \( M_3 = 36 \).
3
\( 63 y_1 \equiv 1\!\pmod{4} \Rightarrow 3 y_1 \equiv 1 \Rightarrow y_1 = 3 \). \( 28 y_2 \equiv 1\!\pmod{9} \Rightarrow y_2 = 4 \). \( 36 y_3 \equiv 1\!\pmod{7} \Rightarrow 1 y_3 \equiv 1 \Rightarrow y_3 = 1 \).
4
\( x = 3(63)(3) + 4(28)(4) + 1(36)(1) = 567 + 448 + 36 = 1051 \equiv \) 43 \( \pmod{252} \).

CRT Construction Diagram

M = m₁ · m₂ · m₃ M₁ = M / m₁ M₂ = M / m₂ M₃ = M / m₃ y₁: M₁y₁ ≡ 1 (mod m₁) y₂: M₂y₂ ≡ 1 (mod m₂) y₃: M₃y₃ ≡ 1 (mod m₃) x ≡ Σ aᵢ Mᵢ yᵢ (mod M)

Why Does the Construction Work?

1
Each term targets one equation. The term \( a_i M_i y_i \) satisfies \( x \equiv a_i \pmod{m_i} \) because \( M_i y_i \equiv 1 \pmod{m_i} \).
2
Other terms vanish. For \( j \neq i \), the term \( a_j M_j y_j \equiv 0 \pmod{m_i} \) since \( m_i \mid M_j \).
3
Uniqueness. If \( x_1 \) and \( x_2 \) both solve the system, then \( m_i \mid (x_1 - x_2) \) for all \( i \). Since the \( m_i \) are coprime, \( M \mid (x_1 - x_2) \), so \( x_1 \equiv x_2 \pmod{M} \).

Common Mistakes

✕ Forgetting Coprimality
Applying CRT when moduli share a common factor (e.g., \( 6 \) and \( 4 \)) leads to wrong or nonexistent solutions.
✕ Wrong Inverse
Computing \( y_i \) as a regular inverse instead of a modular inverse: \( M_i y_i \equiv 1 \pmod{m_i} \), not \( M_i y_i = 1 \).
✕ Skipping Final Reduction
The raw sum can be large. You must reduce \( x \pmod{M} \) to find the answer in the correct range \( [0, M) \).

Summary at a Glance

Component Definition / Formula Purpose
\( M \) \( m_1 m_2 \cdots m_k \) Combined modulus
\( M_i \) \( M / m_i \) Partial product for the \( i \)-th equation
\( y_i \) \( M_i y_i \equiv 1 \pmod{m_i} \) Modular inverse of \( M_i \)
\( x \) \( \sum a_i M_i y_i \pmod{M} \) The unique solution

Question 1 of 5

What is the key requirement for the Chinese Remainder Theorem to guarantee a unique solution?

Question 2 of 5

Solve: \( x \equiv 1 \pmod{3} \) and \( x \equiv 2 \pmod{5} \). What is \( x \pmod{15} \)?

Question 3 of 5

For the system \( x \equiv 2 \pmod{3} \), \( x \equiv 3 \pmod{5} \), \( x \equiv 2 \pmod{7} \), what is \( M \)?

Question 4 of 5

Can CRT be directly applied to: \( x \equiv 1 \pmod{6} \) and \( x \equiv 3 \pmod{4} \)?

Question 5 of 5

In the CRT formula, what is the role of the modular inverse \( y_i \)?