Chinese Remainder Theorem

Let m1,m2,...,mrZm_1, m_2, ..., m_r \in \Z be integers greater than 1 that are pairwise co-prime. Let a1,a2,...,arZa_1, a_2, ..., a_r \in \Z, then the system,

xa1(modm1)x \equiv a_1 \pmod{m_1}
xa2(modm2)x \equiv a_2 \pmod{m_2}
...
xar(modmr)x \equiv a_r \pmod{m_r}

admits a unique solution (modm1m2...mr)\pmod{m_1\cdot m_2 \cdot ... \cdot m_r}

Example

Consider the following linear congruences:

x2(mod3)x \equiv 2 \pmod{3}
x3(mod5)x \equiv 3 \pmod{5}
x5(mod7)x \equiv 5 \pmod{7}

Therefore, m=m1m2m3=105m = m_1 \cdot m_2 \cdot m_3 = 105.

For b1:mm1b11(modm1)b_1: \frac{m}{m_1} \cdot b_1 \equiv 1 \pmod{m_1}
35b11(mod3)=2b11(mod3)35 \cdot b_1 \equiv 1 \pmod{3} = 2\cdot b_1 \equiv 1 \pmod{3}
b12(mod3)b_1 \equiv 2 \pmod{3}

For b2:mm2b21(modm2)b_2: \frac{m}{m_2} \cdot b_2 \equiv 1 \pmod{m_2}
21b21(mod5)=b21(mod5)21 \cdot b_2 \equiv 1 \pmod{5} = b_2 \equiv 1 \pmod{5}

For b3:mm3b31(modm3)b_3: \frac{m}{m_3} \cdot b_3 \equiv 1 \pmod{m_3}
15b31(mod7)=b31(mod7)15 \cdot b_3 \equiv 1 \pmod{7} = b_3 \equiv 1 \pmod{7}

x=mm1b1a1+mm2b2a2+mm3b3a3x = \frac{m}{m_1} \cdot b_1 \cdot a_1 + \frac{m}{m_2} \cdot b_2 \cdot a_2 + \frac{m}{m_3} \cdot b_3 \cdot a_3
x=140+63+75=278x = 140 + 63 + 75 = 278
x=68(mod105)x = 68 \pmod{105}