Skip to main content

Section 4.5 The Chinese Remainder Theorem

The Chinese Remainder Theorem is a result in number theory about solving simultaneous systems of several linear congruences. In this section we explore its origins and give methods to solve these systems.

Exploration 4.5.1. Sun Zi's Problem.

Sun Zi (孙子) was a Chinese mathematician who in his text Sunzi Suanjing《孙子算经》 (3rd to 5th century AD) is said to have written the earliest known reference to systems of linear congruences. In it he writes:

今有物,不知其数。三、三数之,剩二;五、五数之,剩三;七、七数之,剩二。问物几何?

孙子。《孙子算经》。

‘A number is repeatedly divided by 3, the remainder is 2; divided by 5, the remainder is 3; and by 7, the remainder is 2. What will the number be?’

―Sun Zi, Sunzi Suanjing, Vol. 3, Problem 26 (as cited in [5])

We follow Sun Zi's method of solving this system.

(a)

The first condition in Sun Zi's problem can be written as

\begin{equation*} x \equiv 2 \Mod{3}\text{.} \end{equation*}

Write all three conditions as a system of linear congruences.

(b)

Since the integers 3, 5, and 7 are pairwise relatively prime, then \(35^{-1} \Mod{3}\) exists. Compute this quantity.

Similarly, compute \(21^{-1} \Mod{5}\) and \(15^{-1} \Mod{7}\text{.}\)

(c)

Explain why each of the following congruences hold:

\begin{equation*} \begin{cases} 2 \cdot 35^{-1} \cdot 35 \equiv 2 \Mod{3} \\ 3 \cdot 21^{-1} \cdot 21 \equiv 3 \Mod{5} \\ 2 \cdot 15^{-1} \cdot 15 \equiv 2 \Mod{7} \end{cases}\text{.} \end{equation*}
(d)

Explain why we can conclude that

\begin{equation*} x \equiv 2 \cdot 35^{-1} \cdot 35 + 3 \cdot 21^{-1} \cdot 21 + 2 \cdot 15^{-1} \cdot 15 \Mod{105} \end{equation*}

is a solution to the original system of congruences, and using your answers from (b) simplify this expression to get an answer modulo 105.

Finally, verify that the answer satisfies all three conditions.

The method outlined in Exploration 4.5.1 actually works for the general case, as long as the moduli in the system are pairwise relatively prime. Before stating our main theorems let's look at a smaller examples, one with only two congruences.

Find a natural number \(x\) that leaves a remainder of 3 when divided by 5, and a remainder of 1 when divided by 7.

Hint

What are the numbers that satisfy the first condition? Among these, find one satisfying the second as well.

The solution to Checkpoint 4.5.1 did not use the same method as Exploration 4.5.1 and instead just relied on listing numbers. This won't be efficient for larger systems, so let's try to proceed more systematically.

Theorem 4.5.2 speaks to the existence and uniqueness of a solution to the given system. Try proving it yourself in the next two exercises!

Prove that \(x \equiv atm_2 + bsm_1 \Mod{m_1m_2}\) satisfies both congruences in the given system.

Prove that \(x \equiv atm_2 + bsm_1 \Mod{m_1m_2}\) is the only solution to the given system modulo \(m_1m_2\text{.}\)

Finally we state a method for a general system of congruences.

Solve the system of congruences

\begin{equation*} \begin{cases} x \equiv 4 \Mod{5} \\ x \equiv 5 \Mod{6} \\ x \equiv 6 \Mod{7} \end{cases} \end{equation*}

using the method in Theorem 4.5.6.

One consequence of Theorem 4.5.6 is that there is a bijection between n-tuples

\begin{equation*} (a_1,a_2,\ldots,a_n) \in \mathbb{Z}_{m_1} \times \mathbb{Z}_{m_2} \times \cdots \times \mathbb{Z}_{m_n} \end{equation*}

and congruence classes modulo \(M = \prod_{i=1}^n m_i\text{,}\) as long as the moduli \(m_i\) are pairwise relatively prime.

That is, any number in \(\{0,1,\ldots,M\}\) has a unique representation as a collection of remainders \(a_i\) for each modulus \(m_i\text{.}\)

Let \(x \equiv 1 \Mod{2}\) and \(x \equiv 2 \Mod{5}\text{.}\) Then Theorem 4.5.6 tells us that the solution \(x \equiv 7 \Mod{10}\) is unique.

In fact for any pair of remainders modulo 2 and 5, we get a unique congruence class modulo 10 as a solution to the system

\begin{equation*} \begin{cases} x \equiv a_1 \Mod{2} \\ x \equiv a_2 \Mod{5}\end{cases} \end{equation*}

Verify that we have a bijection between \(\mathbb{Z}_2 \times \mathbb{Z}_5\) and \(\mathbb{Z}_{10}\text{:}\)

\(\mathbb{Z}_2 \times \mathbb{Z}_5\) \(\mathbb{Z}_{10}\)
\((0,0)\) \(0\)
\((0,1)\) \(6\)
\((0,2)\) \(2\)
\((0,3)\) \(8\)
\((0,4)\) \(4\)
\(\mathbb{Z}_2 \times \mathbb{Z}_5\) \(\mathbb{Z}_{10}\)
\((1,0)\) \(5\)
\((1,1)\) \(1\)
\((1,2)\) \(7\)
\((1,3)\) \(3\)
\((1,4)\) \(9\)

Verify that 19 is a solution to the system

\begin{equation*} \begin{cases} x \equiv 1 \Mod{3} \\ x \equiv 5 \Mod{7}\end{cases} \end{equation*}

Then, use this fact to compute \(19^{20} \mmod{21}\text{.}\)

Hint

Instead of computing large powers of 19, compute large powers of 1 and 5 (with respective moduli) then use Theorem 4.5.2.

Solutions Solutions to Selected Checkpoints

Checkpoint 4.5.1. Two Congruences.