10

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

2 Answers2

8

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.

Thomas Andrews
  • 177,126
  • 1
    $64\mid x-18$ implies $8\mid x-18$ implies $8\mid (x-18)+8=x-10$ implies $x\equiv 10\pmod {8}$. More generally, if $m_1\mid m_2$ and $m_1\mid n_1-n_2$ then $x\equiv n_2\pmod{m_2}$ implies $x\equiv n_1\pmod{m_1}$. – Thomas Andrews Jan 07 '15 at 17:24
  • Please be specific. Do you really not follow any of those implications? – Thomas Andrews Jan 07 '15 at 17:36
  • Do you see why $x\equiv 10\pmod {24}$ is equivalent to the pair of congruences $x\equiv 10\pmod{3}$ and $x\equiv 10\pmod{8}$? That's the first key. Then you look at the congruences that contain the same prime. So we want to know if $x\equiv 10\pmod{8}$ is compatible with $x\equiv 18\pmod{64}$. Therefore, we have our $n_1=10,n_2=18,m_1=8,m_2=64$. $n_1-n_2$ is divisible by $8$, so they are compatible. – Thomas Andrews Jan 07 '15 at 17:43
  • 1
    Yes. Basically, you'll end up with one congruence for each maximal prime power dividing one of your original moduli. But it is important to make sure there is no incompatibility before you do so. For example, $x\equiv m\pmod{12}$ and $x\equiv n\pmod {18}$ will reduce to $x\equiv n\pmod 9$ and $x\equiv m\pmod 4$. But you still have the make sure that $m\equiv n\pmod{6}$ to make sure the other prime powers are compatible. – Thomas Andrews Jan 07 '15 at 17:54
  • I think that answer is unnecessarily confusing. You should probably solve pairs of congruences first, and then do multiples by induction, just for clarity. – Thomas Andrews Jan 07 '15 at 18:02
6

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
  • 175,478