# How to solve this using the Chinese Remainder Theorem?

Question 1: Given the system\begin{align*} & x\equiv 3\mod 4\tag{1}\\ & x\equiv 2\mod 5\tag{2}\\ & x\equiv 5\mod 11\tag{3}\end{align*} Solve for $x$ using the Chinese Remainder Theorem.

I was taught that the remainder theorem says that given\begin{align*} & x\equiv b_1\mod n_2\tag4\\ & x\equiv b_2\mod n_2\tag5\\ & \cdots\cdots\cdots\cdots\cdots\cdot\tag6\\ & x\equiv b_r\mod n_r\tag7\end{align*} Then $x\equiv b_1c_1\dfrac {N}{n_1}+b_2 c_2\dfrac {N}{n_2}+\cdots+b_rc_r\dfrac {N}{n_r}\mod N$ where $N=\prod\limits_{n=1}^r n_r$ and $c_i\dfrac N{n_i}\equiv 1\mod n_i$.

Using this, we have $(b_1,b_2,b_3)=(3,2,5)$ and $(c_1,c_2,c_3)=(1,2,1)$. Hence, $x\equiv 120\equiv 0\mod 30$. Which is obviously wrong.

By trial and error, I found the answer to be $27$.

Questions:

1. How do I solve for $x$, and what went wrong in my follow through?
2. Is there an easier way to calculate $c_i\frac {N}{n_i}\equiv1\mod n_i$ (I believe this is called the inverse)?
• You've made mistakes in finding $c_i$ for each $i$. To find a multiplicative inverse (if it exists), and the extended Euclidean algorithm to keep things organised. – GNUSupporter 8964民主女神 地下教會 Feb 2 '17 at 23:24
• Yes, $c_2=-1$ or $4$, not $2$. – Thomas Andrews Feb 2 '17 at 23:28
• And $20c_3\equiv 1\pmod{11}$ so $c_3=5$. – Thomas Andrews Feb 2 '17 at 23:29

You asked for an easier (general) way. Usually it is easier two solve them a pair at a time.

${\rm mod}\ 11\!:\,\ x\equiv 5\,\Rightarrow\, x = 5+11\color{#c00}j$
${\rm mod}\ \color{#c00}5\!:\,\ \color{#c00}2\equiv x\equiv 5+11j\equiv \color{#c00}j\$ so $\,x = 5+11(\!\!\!\!\!\!\!\color{#c00}{\overbrace{2+5k}^{\large j\ \equiv\ 2\pmod{\! 5}}}\!\!\!\!\!\!\!\!)=27+55\color{#0a0}k$

${\rm mod}\ \color{#0a0}4\!:\,\ 3\equiv x\equiv 27+55k\equiv 3-k\$ so $\ \color{#0a0}{k\equiv 0}\$ so $\, x = 27+55(\!\!\!\!\!\!\!\color{#0a0}{\underbrace{0+4n}_{\large k\ \equiv\ 0\pmod{\! 4}}}\!\!\!\!\!\!\!\!) = 27+220n$

Remark $\$ This method works generally, see this answer for a proof.

It's important that $$4, 5,$$and $$11$$ are pairwise prime. Here is how I do it. (Warning. Explaining how I do it will take up much more room than what it takes to actually just do it.)

I start by making the following table

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline 55 \\ 44 \\ 20 \\ \hline \end{array}$$

Where $$55 = \dfrac{4 \cdot 5 \cdot 11}{4}=5 \cdot 11, \qquad 44 = \dfrac{4 \cdot 5 \cdot 11}{5}=4 \cdot 11, \qquad 20 = \dfrac{4 \cdot 5 \cdot 11}{11}=5 \cdot 11.$$

Note that $$4 \cdot 5 \cdot 11 = 220$$.

Then I compute the following numbers

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline 55 & 55 \pmod{4} & 55 \pmod{5} & 55 \pmod{11} \\ 44 & 44 \pmod{4} & 44 \pmod{5} & 44 \pmod{11}\\ 20 & 20 \pmod{4} & 20 \pmod{5} & 20 \pmod{11}\\ \hline \end{array}$$

Which turns out to be

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline 55 & -1 & 0 & 0 \\ 44 & 0 & -1 & 0\\ 20 & 0 & 0 & -2\\ \hline \end{array}$$

It will always happen that only the diagonal elements are non zero.

What you want to do is change each row by multiplying each number in that row by the number that will make the diagonal element equal to $$1$$. When the diagonal element is $$-1$$, this is really easy.

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline -55 & 1 & 0 & 0 \\ -44 & 0 & 1 & 0\\ 20 & 0 & 0 & -2\\ \hline \end{array}$$

It's easy to check that $$-55 \pmod 4 = 1$$ and $$-44 \pmod 5 = 1$$.

So we still need to figure out what to multiply $$-2$$ by to make the answer congruent to $$1$$ modulo $$11$$. Well $$11+1=12 = (-6)(-2)$$. So...

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline -55 & 1 & 0 & 0 \\ -44 & 0 & 1 & 0\\ -120 & 0 & 0 & 1\\ \hline \end{array}$$

The above numbers are perfectly fine; they will work; but, I would do it differently. It turns out that you can always find numbers so that the left column adds up to $$1$$. Since $$(-55) + (-44) = -99$$, then we should be able to replace $$-120$$ with $$100$$. That makes sense, since we multiplied $$20$$ by $$-6$$ and since $$-6 \equiv 5 \pmod{11}$$, we get

$$\begin{array}{c|ccc|} & 4 & 5 & 11 \\ \hline -55 & 1 & 0 & 0 \\ -44 & 0 & 1 & 0\\ 100 & 0 & 0 & 1\\ \hline \end{array}$$

The answer is then $$3(-55) + 2(-44) + 5(100) = 27 \pmod{220}$$.