[Math] Chinese remainder theorem for non-prime / non-coprime moduli

chinese remainder theoremelementary-number-theory

If I want to find some number $x$ where it leaves a remainder when divided by some prime $p$, and another remainder when divided by some prime $q$, and so on, I can use the Chinese Remainder Theorem.

However, what about when $p$ and $q$ are not prime nor coprime?

Best Answer

To use your example, trying to solve:

$$x\equiv 10\pmod{24}\\x\equiv 18\pmod{64}$$

You take each in terms of its prime factors:

$$x\equiv 10\pmod {3}\\ x\equiv 10\pmod{8}\\x\equiv 18\pmod {64} $$

Note that $x\equiv{18}\pmod {64}$ implies $x\equiv 10\pmod 8$, so we are left with:

$$x\equiv 10\pmod {3}\\x\equiv 18\pmod {64}$$

which is a pair of equations with coprime moduli.

You can always do this. Prime factorization is hard, however, so if you wanted an algorithm, you'd want to come up with a more general way than just prime-factorization. There are ways, but I'd have to call them up from memory. But the general gist is that you need to always reduce the problem to the co-prime case, and some way to check for contradictions that rule out solutions.