CHINESE REMAINDER THEOREM (CRT)

Aim: solve a set of congruences
    x = a1 (mod m1), x = a2 (mod m2), x = a3 (mod m3)
where m1, m2, m3 are pairwise coprime.

Formula:
    M  = m1 * m2 * m3
    Mi = M / mi
    yi = inverse of Mi mod mi   (Mi * yi = 1 mod mi)
    x  = (a1*M1*y1 + a2*M2*y2 + a3*M3*y3) mod M

Steps:
1. Multiply all moduli to get M.
2. For each i find Mi = M / mi.
3. Find the modular inverse yi of Mi under mi.
4. Add ai * Mi * yi for all i and take mod M.

Example in program: x=2 mod 3, x=3 mod 5, x=2 mod 7
M = 105, answer x = 23.
Check: 23%3=2, 23%5=3, 23%7=2.
