0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|

0 | 0 | 40 | 15 | 55 | 30 | 5 | 45 | 20 | 60 | 35 | 10 | 50 | 25 |

1 | 26 | 1 | 41 | 16 | 56 | 31 | 6 | 46 | 21 | 61 | 36 | 11 | 51 |

2 | 52 | 27 | 2 | 42 | 17 | 57 | 32 | 7 | 47 | 22 | 62 | 37 | 12 |

3 | 13 | 53 | 28 | 3 | 43 | 18 | 58 | 33 | 8 | 48 | 23 | 63 | 38 |

4 | 39 | 14 | 54 | 29 | 4 | 44 | 19 | 59 | 34 | 9 | 49 | 24 | 64 |

The entries in the table are integers from 0 through 64. We use these 65 numbers because 5 × 13 = 65. The number is placed in a row and column according to its remainder after dividing by 5 and by 13. For example, the number 57 is in row 2 and column 5 because 57 % 5 = 2 and 57 % 13 = 5. If you start from the top left with 0 and scan down the diagonal to find 1, 2, 3 and 4, you will notice a very nice pattern in this table. The numbers in increasing order march down the diagonals and wrap around to the top — 5, 6, 7, 8 and 9 make the next diagonal. This proceeds across the table until we get to 10, 11 and 12 and notice that the numbers then wrap around to the left side of the table where 13 and 14 are in the lower left.

This diagonal pattern continues until all 65 numbers are used. The interesting part is that each number appears in its own entry in the table. The diagonals did not overlap. Why is that? Well, because 5 and 13 are prime. (Actually, because gcd(5, 13) = 1, but we'll get to that later.) If you construct this table with 6 and 12 (a good exercise), you will see that this this pattern does not hold for all pairs of numbers.

Great. So what is the Chinese Remainder Theorem? Well, if you give me an
integer *x* between 0 and 64, it is easy for me to figure out
where *x* belongs in the table. I just have to compute *x* % 5
and *x* % 13. These are easy computations. What if we ask the question
in the other direction? Given two remainders *a*_{1} and
*a*_{2}, find a number *x* such that *x* % 5 =
*a*_{1} and *x* % 13 = *a*_{2}. Again, this
is easy because you just look at row *a*_{1} and column
*a*_{2} of the table and use that number. For example,
if *a*_{1} = 3 and *a*_{2} = 11, you just
say 63. Okay, now do it without looking at the table. Then, it becomes
harder.

So here's the problem. You are given two prime numbers, *p*_{1}
and *p*_{2}, and two remainders *a*_{1}
and *a*_{2}. Now, find a number *x*, where
0 ≤ *x* ≤ *p*_{1} ⋅ *p*_{2},
such that

How do we computex%p_{1}=a_{1}

x%p_{2}=a_{2}.

**Baby Chinese Remainder Theorem.**
Let *p*_{1} and *p*_{2} be prime numbers.
Given integers *a*_{1} and *a*_{2},
there exists a unique *x*, 0 ≤ *x* <
*p*_{1} ⋅ *p*_{2}, such that

x≡a_{1}(modp_{1})

x≡a_{2}(modp_{2}).

__ Comment:__
Here the notation

__ Proof:__ First we show that

wherex= (a_{1}⋅p_{2}⋅y_{1}+a_{2}⋅p_{1}⋅y_{2}) % (p_{1}p_{2})

(Recall that we can find inverses using the Extended Euclid Algorithm.) Now let us computep_{2}⋅y_{1}≡ 1 (modp_{1})

p_{1}⋅y_{2}≡ 1 (modp_{2})

Similarly,x≡a_{1}p_{2}y_{1}+a_{2}p_{1}y_{2}(modp_{1}) [sincep_{1}dividesp_{1}p_{2}]

≡a_{1}p_{2}y_{1}+ 0 (modp_{1}) [sincep_{1}dividesa_{2}p_{1}y_{2}]

≡a_{1}⋅ 1 (modp_{1}) [sincep_{2}y_{1}≡ 1 (modp_{1})]

≡a_{1}(modp_{1})

Thus, we have shown that the numberx≡a_{1}p_{2}y_{1}+a_{2}p_{1}y_{2}(modp_{2}) [sincep_{2}dividesp_{1}p_{2}]

≡ 0 +a_{2}p_{1}y_{2}(modp_{2}) [sincep_{2}dividesa_{1}p_{2}y_{1}]

≡a_{2}⋅ 1 (modp_{2}) [sincep_{1}y_{2}≡ 1 (modp_{2})]

≡a_{2}(modp_{2})

Then,x'≡a_{1}(modp_{1})

x'≡a_{2}(modp_{2}).

Thus,x−x'=k_{1}⋅p_{1}

x−x'=k_{2}⋅p_{2}.

Now, recall that bothx−x'=k_{2}p_{2}=k'p_{1}p_{2}.

QED

__ Example:__
Let's return to our example where

13 ⋅ 2 = 26, 26 % 5 = 1So,

5 ⋅ 8 = 40, 40 % 13 = 1

You can confirm that 63 % 5 = 3 and 63 % 13 = 11, but it is more interesting to think about whyx= ( 3 ⋅ 13 ⋅ 2 + 11 ⋅ 5 ⋅ 8 ) % 65

= (78 + 440) % 65

= 518 % 65

= 63

( 3 ⋅ 13 ⋅ 2 + 11 ⋅ 5 ⋅ 8 ) % 5 = 3and why

( 3 ⋅ 13 ⋅ 2 + 11 ⋅ 5 ⋅ 8 ) % 13 = 11.We know that (3⋅13⋅2) % 5 = 3 because 13 and 2 are inverses modulo 5 so 3⋅13⋅2 ≡ 3⋅1 ≡ 3 (mod 5). Also, 11⋅5⋅8 ≡ 0 (mod 5) because 5 appears as a factor in 11⋅5⋅8. Thus, 3⋅13⋅2 + 11⋅5⋅8 ≡ 3 + 0 ≡ 3 (mod 5). Similarly, when we look at

**Chinese Remainder Theorem.**
Let *m*_{1}, *m*_{2},
*m*_{3}, ... *m*_{n} be positive integers
that are pairwise relatively prime. (I.e., for all *i* and
*j* where *i* ≠ *j*,
gcd(*m*_{i}, *m*_{j}) = 1.)
Let *m* = *m*_{1} *m*_{2} *m*_{3}
⋅ ⋅ ⋅ *m*_{n}.
Given integers
*a*_{1}, *a*_{2},
*a*_{3}, ... *a*_{n},
there exists a unique *x*, 0 ≤ *x* < *m*,
such that

x≡a_{1}(modm_{1})

x≡a_{2}(modm_{2})

x≡a_{3}(modm_{3})

...

x≡a_{n}(modm_{n}).

__ Proof Idea:__ Before we proceed with the formal proof,
let's think how we can extend the proof of the baby version to the
full version. Having pairwise relatively prime moduli instead of
prime moduli won't change much. Prime numbers gave us inverses and
so will relatively prime numbers. We need to duplicate the trick
that made the second term disappear when we mod out by

But, what do we pick forx= (a_{1}t_{1}+a_{2}t_{2}+a_{3}t_{3}+a_{4}t_{4}+a_{5}t_{5}) %m

This could be accomplished ifx≡a_{1}⋅ 0 +a_{2}⋅ 0 +a_{3}⋅ 0 +a_{4}t_{4}+a_{5}⋅ 0 (modm_{4})

≡a_{4}t_{4}(modm_{4})

So, we lett_{1}divisible bym_{2}m_{3}m_{4}m_{5}

t_{2}divisible bym_{1}m_{3}m_{4}m_{5}

t_{3}divisible bym_{1}m_{2}m_{4}m_{5}

t_{4}divisible bym_{1}m_{2}m_{3}m_{5}

t_{5}divisible bym_{1}m_{2}m_{3}m_{4}

and we have the desired effect. If you understand the proof idea forx= (a_{1}(m/m_{1})y_{1}+a_{2}(m/m_{2})y_{2}+a_{3}(m/m_{3})y_{3}+a_{4}(m/m_{4})y_{4}+a_{5}(m/m_{5})y_{5}) %m

__ Proof:__ We define

where

nx=( ∑ a_{j}(m/m_{j})y_{j}) % mj= 1

Since

nx%m_{i}= ( ∑ a_{j}(m/m_{j})y_{j}) % m_{i}j= 1i− 1n= ( ∑ a_{j}(m/m_{j})y_{j}) % m_{i}+ a_{i}(m/m_{i})y_{i}%m_{i}+( ∑ a_{j}(m/m_{j})y_{j}) % m_{i}.j= 1j=i+ 1

Sincex%m_{i}= 0 +a_{i}(m/m_{i})y_{i}%m_{i}+ 0 =a_{i}(m/m_{i})y_{i}%m_{i}.

Thus, for allx%m_{i}=a_{i}⋅ 1 %m_{i}=a_{i}%m_{i}.

Finally, suppose that there is some *x'* where 0 ≤ *x'*
< *m* such that for all *i*, 0 ≤ *i* ≤
*n*, *x'* ≡ *a*_{i} (mod
*m*_{i}). Then, *x* ≡ *x'*
(mod *m*_{i}) for all *i*.
Then, there must be integers
*k*_{1},
*k*_{2},
*k*_{3},
...
*k*_{n}, such that for all *i*

Sincex−x'=k_{i}m_{i}.

QED

__ Example:__
The reason that the Chinese Remainder Theorem is named such is because
Sun Tzu (544BC – 496BC) mentioned it in his
Mathematical Manual. In essence, he asked for a number

Let's findx≡ 2 (mod 3)

x≡ 3 (mod 5)

x≡ 2 (mod 7).

Now we need to calculate the inversesm= 3 ⋅ 5 ⋅ 7 = 105

m/m_{1}= 105 / 3 = 5 ⋅ 7 = 35

m/m_{2}= 105 / 5 = 3 ⋅ 7 = 21

m/m_{3}= 105 / 7 = 3 ⋅ 5 = 15

So,m/m_{1}%m_{1}= 35 % 3 = 2

2 ⋅ 2 = 4 ≡ 1 (mod 3).

Finally, you can check that 23 % 3 = 2, 23 % 5 = 3 and 23 % 7 = 2. So, our solution is indeed correct.x= (a_{1}(m/m_{1})y_{1}+a_{2}(m/m_{2})y_{2}+a_{3}(m/m_{3})y_{3}) %m

= ( 2⋅35⋅2 + 3⋅21⋅1 + 2⋅15⋅1) % 105

= 233 % 105

= 23

Last Modified: 24 Jan 2016 20:45:06 EST by Richard Chang to Spring 2016 CMSC 203-06 Homepage