The Chinese Remainder Theorem


The Chinese Remainder Theorem says that certain systems of simultaneous congruences with different moduli have solutions. The idea embodied in the theorem was apparently known to Chinese mathematicians a long time ago --- hence the name.

I'll begin by collecting some useful lemmas.

Lemma 1. Let m and $a_1$ , ..., $a_n$ be positive integers. If m is relatively prime to each of $a_1$ , ..., $a_n$ , then it is relatively prime to their product $a_1\cdots a_n$ .

Proof. If $(m,a_1\cdots a_n) \ne 1$ , then there is a prime p which divides both m and $a_1\cdots a_n$ . Since $p
   \mid a_1\cdots a_n$ , p must divide $a_i$ for some i. Now p divides both m and $a_i$ , so $(m,a_i)
   \ne 1$ \contra. This contradiction implies that $(m,a_1\cdots a_n) = 1$ .


Example. 6 is relatively prime to 25, to 7, and to 11. $25\cdot 7\cdot 11
   = 1925$ , and $(6,1925) = 1$ :

$$\vbox{\offinterlineskip \halign{& \vrule # & \strut \hfil \quad # \quad \hfil \cr \noalign{\hrule} height2pt & \omit & & \omit & \cr & a & & q & \cr height2pt & \omit & & \omit & \cr \noalign{\hrule} height2pt & \omit & & \omit & \cr & 1925 & & - & \cr height2pt & \omit & & \omit & \cr \noalign{\hrule} height2pt & \omit & & \omit & \cr & 6 & & 320 & \cr height2pt & \omit & & \omit & \cr \noalign{\hrule} height2pt & \omit & & \omit & \cr & 5 & & 1 & \cr height2pt & \omit & & \omit & \cr \noalign{\hrule} height2pt & \omit & & \omit & \cr & 1 & & 5 & \cr height2pt & \omit & & \omit & \cr \noalign{\hrule} }}\quad\halmos $$


I showed earlier that the greatest common divisor $(a,b)$ of a and b is greatest in the sense that it is divisible by any common divisor of a and b. The next result is the analogous statement for least common multiples.

Lemma 2. Let m and $a_1$ , ..., $a_n$ be positive integers. If m is a multiple of each of $a_1$ , ..., $a_n$ , then m is a multiple of $[a_1, \ldots, a_n]$ .

Proof. By the Division Algorithm, there are unique numbers q and r such that

$$m = q\cdot [a_1, \ldots, a_n] + r, \hbox{ where } 0 \le r < [a_1, \ldots, a_n].$$

Now $a_i$ divides both m and $[a_1, \ldots, a_n]$ , so $a_i$ divides r. Since this is true for all i, r is a common multiple of the $a_i$ smaller than the least common multiple $[a_1,
   \ldots, a_n]$ . This is only possible if $r = 0$ . Then $m = q\cdot [a_1, \ldots, a_n]$ , i.e. m is a multiple of $[a_1, \ldots, a_n]$ .


Example. 88 is a multiple of 4 and 22. The least common multiple of 4 and 22 is 44, and 88 is also a multiple of 44.


Lemma 3. Let $a_1$ , ..., $a_n$ be positive integers. If $a_1$ , ..., $a_n$ are pairwise relatively prime (that is, $(a_i,a_j) = 1$ for $i \ne j$ ), then

$$[a_1, \ldots, a_n] = a_1\cdots a_n.$$

Proof. Induct on n. The statement is trivially true for $n = 1$ , so I'll start with $n = 2$ . The statement for $n = 2$ follows from the equation $xy = [x,y](x,y)$ :

$$[a_1,a_2] = \dfrac{a_1a_2}{(a_1,a_2)} = \dfrac{a_1a_2}{1} = a_1a_2.$$

Now assume $n > 2$ , and assume the result is true for n. I will prove that it holds for $n + 1$ .

Claim: $\left[[a_1, \ldots, a_n], a_{n+1}\right] = [a_1, \ldots, a_n,
   a_{n+1}]$ .

(Some people take this as an iterative definition of $[a_1, \ldots, a_n, a_{n+1}]$ .) $[a_1, \ldots, a_n, a_{n+1}]$ is a multiple of each of $a_1$ , ..., $a_n$ , so by Lemma 2 it's a multiple of $[a_1, \ldots, a_n]$ . It's also a multiple of $a_{n+1}$ , so

$$\left[[a_1, \ldots, a_n], a_{n+1}\right] \bigm| [a_1, \ldots, a_n, a_{n+1}].$$

On the other hand, for $i =
   1, \ldots, n$ ,

$$a_i \bigm| [a_1, \ldots, a_n] \quad\hbox{and}\quad [a_1, \ldots, a_n] \bigm| \left[[a_1, \ldots, a_n], a_{n+1}\right].$$

Therefore,

$$a_i \bigm| \left[[a_1, \ldots, a_n], a_{n+1}\right].$$

Obviously,

$$a_{n+1} \bigm| \left[[a_1, \ldots, a_n], a_{n+1}\right].$$

Thus, $\left[[a_1, \ldots,
   a_n], a_{n+1}\right]$ is a common multiple of all the $a_i$ 's. Since $[a_1, \ldots, a_n, a_{n+1}]$ is the least common multiple, Lemma 2 implies that

$$[a_1, \ldots, a_n, a_{n+1}] \bigm| \left[[a_1, \ldots, a_n], a_{n+1}\right].$$

Since I have two positive numbers which divide one another, they're equal:

$$\left[[a_1, \ldots, a_n], a_{n+1}\right] = [a_1, \ldots, a_n, a_{n+1}].$$

This proves the claim.

Returning to the proof of the induction step, I have

$$[a_1, \ldots, a_n, a_{n+1}] = \left[[a_1, \ldots, a_n], a_{n+1}\right] = [a_1\cdots a_n, a_{n+1}] = a_1\cdots a_n a_{n+1}.$$

The second equality follows by the induction hypothesis (the statement for n). The third equality follows from Lemma 1 and the result for $n = 2$ .


Example. 6, 25, and 7 are relatively prime (in pairs). The least common multiple is $[6,25,7] = 1050 = 6\cdot 25\cdot
   7$ .


Theorem. ( The Chinese Remainder Theorem) Suppose $m_1$ , ..., $m_n$ are pairwise relatively prime (that is, $(n_i,m_j) = 1$ for $i \ne j$ ). Then the system of congruences

$$\eqalign{ x &= a_1 \mod{m_1} \cr x &= a_2 \mod{m_2} \cr & \vdots \cr x &= a_n \mod{m_n} \cr}$$

has a unique solution mod $m_1m_2\cdots m_n$ .

Notation.

$$x_1x_2 \cdots \widehat{x_i}\cdots x_n$$

means the product $x_1x_2
   \cdots x_i\cdots x_n$ with $x_i$ omitted. For example,

$$x_1x_2 \cdots \widehat{x_4}\cdots x_6 \quad\hbox{means}\quad x_1x_2x_3x_5x_6.$$

This is a convenient (and standard) notation for omitting a single variable term in a product of things.

Proof. Define

$$p_k = m_1\cdots \widehat{m_k}\cdots m_n.$$

That is, $p_k$ is the product of the m's with $m_k$ omitted. By Lemma 1, $(p_k,m_k) = 1$ . Hence, there are numbers $s_k$ , $t_k$ such that

$$s_kp_k + t_km_k = 1.$$

In terms of congruences,

$$s_kp_k = 1 \mod{m_k}.$$

Now let

$$x = a_1p_1s_1 + a_2s_2p_2 + \cdots + a_np_ns_n.$$

If $j \ne k$ , then $m_k \mid p_j$ , so mod $m_k$ all the terms but the k-th term die:

$$x = a_kp_ks_k = a_k\cdot 1 = a_k \mod{m_k}.$$

This proves that x is a solution to the system of congruences (and incidentally, gives a formula for x).

Now suppose that x and y are two solutions to the system of congruences.

$$\eqalign{ x = a_1 \mod{m_1} &\quad\hbox{and}\quad y = a_1 \mod{m_1} \cr x = a_2 \mod{m_2} &\quad\hbox{and}\quad y = a_2 \mod{m_2} \cr & \vdots \cr x = a_n \mod{m_n} &\quad\hbox{and}\quad y = a_n \mod{m_n} \cr}$$

Then

$$x = a_k = y \mod{m_k} \quad\hbox{so}\quad x - y = 0 \mod{m_k} \quad\hbox{or}\quad m_k \mid x - y.$$

Thus, $x - y$ is a multiple of all the m's, so

$$[m_1, \ldots, m_n] \mid x - y.$$

But the m's are pairwise relatively prime, so by Lemma 3,

$$m_1\cdots m_n \mid x - y, \hbox{ i.e. } x = y \mod{m_1\cdots m_n}.$$

That is, the solution to the congruences is unique mod $m_1\cdots m_n$ .


Example. Solve

$$\eqalign{x &= 2 \mod{4} \cr x &= 7 \mod{9} \cr}.$$

$(4,9) = 1$ , so there is a unique solution mod 36. Following the construction of x in the proof,

$$p_1 = 9, \quad 9\cdot 1 = 1 \mod{4}, \hbox{ so take } s_1 = 1$$

$$p_2 = 4, \quad 4\cdot 7 = 1 \mod{9}, \hbox{ so take } s_2 = 7$$

Solution:

$$x = a_1p_1s_1 + a_2p_2s_2 = 18 + 196 = 214 = 34 \mod{36}. \quad\halmos$$


Example. Solve

$$\eqalign{x &= 3 \mod{4} \cr x &= 1 \mod{5} \cr x &= 2 \mod{3} \cr}.$$

The moduli are pairwise relatively prime, so there is a unique solution mod 60. This time, I'll solve the system using an iterative method.

$$x = 3 \mod{4}, \quad\hbox{so}\quad x = 3 + 4s.$$

But $x = 1 \mod{5}$ , so

$$3 + 4s = 1 \mod{5}, \quad 4s = 3 \mod{5}, \quad 4\cdot 4s = 4\cdot 3 \mod{5}, \quad s = 2 \mod{5}, \quad s = 2 + 5t.$$

Hence,

$$x = 3 + 4s = 3 + 4(2 + 5t) = 11 + 20t.$$

Finally, $x = 2 \mod{3}$ , so

$$11 + 20t = 2 \mod{3}, \quad 20t = -9 = 0 \mod{3}, \quad 2t = 0 \mod{3}, \quad 2\cdot 2t = 2\cdot 2 \mod{3}, \quad t = 0 \mod{3}.$$

Hence, $t = 3u$ .

Now put everything back:

$$x = 11 + 20t = 11 + 20(3u) = 11 + 60u, \quad\hbox{or}\quad x = 11 \mod{60}.\quad\halmos$$


Example. Calvin Butterball keeps pet meerkats in his backyard. If he divides them into 5 equal groups, 4 are left over. If he divides them into 8 equal groups, 6 are left over. If he divides them into 9 equal groups, 8 are left over. What is the smallest number of meerkats that Calvin could have?

Let x be the number of meerkats. Then

$$\eqalign{ x & = 4 \mod{5} \cr x & = 6 \mod{8} \cr x & = 8 \mod{9} \cr}$$

From $x = 4 \mod{5}$ , I get $x = 4 + 5a$ . Plugging this into the second congruence, I get

$$\eqalign{ 4 + 5a & = 6 \mod{8} \cr 5a & = 2 \mod{8} \cr 5 \cdot 5a & = 5 \cdot 2 \mod{8} \cr 25a & = 10 \mod{8} \cr a & = 2 \mod{8} \cr}$$

Hence, $a = 2 + 8b$ . Plugging this into $x = 4 + 5a$ gives

$$x = 4 + 5(2 + 8b) = 14 + 40b.$$

Plugging this into the third congruence, I get

$$\eqalign{ 14 + 40b & = 8 \mod{9} \cr 40b & = -6 \mod{9} \cr 4b & = 3 \mod{9} \cr 7 \cdot 4b & = 7 \cdot 3 \mod{9} \cr 28b & = 21 \mod{9} \cr b & = 3 \mod{9} \cr}$$

Hence, $b = 3 + 9c$ . Plugging this into $x = 14 + 40b$ gives

$$x = 14 + 40(3 + 9c) = 134 + 360c.$$

The smallest positive value of x is obtained by setting $c = 0$ , which gives $x = 134$ .


You can sometimes solve a system even if the moduli aren't relatively prime; the criteria are similar to those for solving system of linear Diophantine equations. I'll state the result, but omit the proof.

Theorem. Consider the system

$$\eqalign{x &= a_1 \mod{m_1} \cr x &= a_2 \mod{m_2} \cr}$$

  1. If $(m_1,m_2) \notdiv a_1 -
   a_2$ , there are no solutions.
  2. If $(m_1,m_2) \mid a_1 -
   a_2$ , there is a unique solution mod $[m_1,m_2]$ .

Note that if $(m_1,m_2) =
   1$ , case (b) automatically holds, and $[m_1,m_2] =
   m_1m_2$ --- i.e. I get the Chinese Remainder Theorem for $n = 2$ .


Example. Solve

$$\eqalign{x &= 5 \mod{12} \cr x &= 11 \mod{18} \cr}.$$

Since $(12,18) = 6 \mid 11 -
   5$ , there is a unique solution mod $[12,18] = 36$ . I'll use the iterative method to find the solution.

$$x = 5 \mod{12}, \quad\hbox{so}\quad x = 5 + 12s.$$

Since $x = 11 \mod{18}$ ,

$$5 + 12s = 11 \mod{18}, \quad 12s = 6 \mod{18}.$$

Now I use my rule for "dividing" congruences: 6 divides both 12 and 6, and $(6,18) =
   6$ , so I can divide through by 6:

$$2s = 1 \mod{3}.$$

Multiply by 2, and convert the congruence to an equation:

$$s = 2 \mod{3}, \quad s = 2 + 3t.$$

Plug back in:

$$x = 5 + 12s = 5 + 12(2 + 3t) = 29 + 36t, \quad x = 29 \mod{36}.\quad\halmos$$


Send comments about this page to: Bruce.Ikenaga@millersville.edu.

Bruce Ikenaga's Home Page

Copyright 2008 by Bruce Ikenaga