11

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?

  • 1
    It's certainly possible for there to be no solution. Take $x\equiv 1\pmod 6$ and $x\equiv 2\pmod {15}$. Then there is no solution because it would have to be true that $x\equiv 1\pmod 3$ and $x\equiv 2\pmod 3$. – Thomas Andrews Jan 07 '15 at 17:05
  • 1
    See the answer at http://math.stackexchange.com/questions/120070/chinese-remainder-theorem-with-non-pairwise-coprime-moduli – Gerry Myerson Jan 07 '15 at 17:20
  • Related: https://math.stackexchange.com/questions/1180796/crt-solvablity-criterion-congruence-system-solvable-iff-pairwise-solvable – 19021605 Sep 19 '25 at 06:43

2 Answers2

9

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.


As a rule, given $x\equiv a_i\pmod{m_i}$ for $i=1,\dots, n$ we can always find $d_1,\dots, d_k$ which are pairwise relatively prime, an each $d_j$ is a factor of some $m_i$ and $d_1d_2\cdots d_k=\operatorname{lcm}(m_1,\dots,m_n).$ And then we can rewrite the comgruences modulo the $d_j,$ check if the $\gcd(m_i,d_j)$ are compatible for a;l $i,$ and them solve.

Writing this out rigorously is a perfect example of something easier to see than describe or prove, but it seems like the easiest way is to do it by induction on $n.$

Thomas Andrews
  • 188,543
7

The general result is the following:

The system of congruences $ x\equiv a_i \mod{m_i} \quad(i=1,\dots,r) $ has a solution if and only if for each pair $(i,j)$, $\,\, a_i\equiv a_j \mod{m_i\wedge m_j} $. The solution is unique modulo $\mathrm{lcm}(m_1, \dots, m_r) $.

Bernard
  • 180,128