1

If $x \equiv 3 \pmod 6$ and $x \equiv 5\pmod 8$ then how is this $x \equiv 21\pmod {24}$?

I understand $24$ is $\operatorname{lcm}(6,8)$ but how to get from $3$ and $5$ to $21$?

This is is a Chinese Remainder Theorem problem.

amWhy
  • 209,954

3 Answers3

1

$x\equiv3\pmod 6\implies x\equiv0\pmod 3$ and $x\equiv 1\pmod 2$

Again, $x\equiv5\pmod 8\implies x\equiv1\pmod 2$

So, it suffices to use CRT with $x\equiv0\pmod 3$ and $x\equiv5\pmod 8$ which is legitimate as $(3,8)=1$


Alternatively,

So, $x$ can be written as $6a+3$ where $a$ is any integer

Similarly, $x=8b+5$ for some integer $b$

$\implies 6a+3=x=8b+5\implies 6a=8b+2,3a=4b+1=4b+4-3$

$\implies 3a+3=4b+4\implies a+1=\frac{4(b+1)}3$ which must be an integer as $a+1$ is

So, $3\mid 4(b+1)\implies 3\mid(b+1)$ as $(3,4)=1$

$\implies b=3c-1$ where $c$ is any integer

So, $x=8b+5=8(3c-1)+5=24c-3\equiv-3\pmod{24}\equiv21$

  • How are you changing this to x = 0 mod 3 and x = 1 mod 2? – user2175923 Mar 25 '13 at 15:24
  • If you have an equivalency $\mod n$, you can reduce it to an equivalency $\mod d$ where $d$ is any divisor of $n$. – Yoni Rozenshein Mar 25 '13 at 15:26
  • @user2175923, as $6a+3=3(2a+1)\equiv0\pmod 3$ and $6a+3=2(3a+1)+1\equiv1\pmod 2$ – lab bhattacharjee Mar 25 '13 at 15:27
  • So x = 5 mod 8 can't be reduced any more because gcd(5,8)=1 correct? How do you know what to reduce x=3 mod 6 to? From my understanding all of these are the same: x = 3 mod 6 = 3 mod 2 = 1 mod 2 = 3 mod 3 = 0 mod 3, right? How to pick which one? – user2175923 Mar 25 '13 at 15:59
  • $x\equiv3\pmod 6\implies x\equiv0\pmod 3$ but $x\equiv0\pmod 3$ does not necessarily imply $x\equiv3\pmod 6,$ it may be $x\equiv0\pmod 6$. If $x\equiv0\pmod 3, x=3b$ for some integer $b$. If $b$ is odd $=2c+1$(say) $x=3(2c+1)\equiv3\pmod 6$, but if $b$ is even $=2c$(say) $x=3(2c)\equiv0\pmod 6$ – lab bhattacharjee Mar 25 '13 at 16:03
  • So why can't I do this:

    gcd(6,8) = 2, divide the moduli by this number.

    x = 3 mod 6 = 3 mod 3, and x = 5 mod 8 = 5 mod 4 which solves out to be 9 (incorrectly) even though 3 and 4 are coprime

    – user2175923 Mar 25 '13 at 16:06
  • @user2175923, would you please have look into the properties of congruences : http://mathworld.wolfram.com/Congruence.html – lab bhattacharjee Mar 25 '13 at 16:10
  • That is way too complex for my level of understanding. I am just after a general algorithm of what to do in these situations when you have x = a mod n and x = b mod m where n and m are not coprime. – user2175923 Mar 25 '13 at 16:12
0

$6$ and $8$ are not coprime, but their least common multiple is $2^3 \cdot 3$.

From the first equivalency we know that $x \equiv 0 \pmod 3$. That's all the information we have modulo powers of $3$.

Now, information modulo powers of $2$: From the first equivalency we know that $x \equiv 1 \pmod 2$, and from the second, we know that $x \equiv 5 \pmod 8$. Fortunately, these two equivalencies agree. If they didn't, you would have no solution. Since the second one contains all the information in the first one, we can throw out the first one.

So we need to solve $x \equiv 0 \pmod 3$ and $x \equiv 5 \pmod 8$. By the Chinese remainder theorem, we know that the answer is unique modulo $24$.

Generally, you can plug this into the CRT formula, but I guess the easiest way to solve this instance is to look at the sequence $5, 5+8, 5+16$ and pick out the one that's divisible by $3$.

  • I know how to solve for the CRT of congruences when a and b are coprime; what is the general method for reducing a system when a and b are not coprime as in this problem? How do you know to change it to 0 mod 3 and then not the other, etc? – user2175923 Mar 25 '13 at 15:27
  • Work through all primes $p$ in the least common multiple. In each congruence which is modulo a multiple of $p$, reduce it to the highest possible power of $p$ (like I did above with $p=2$, reducing to $2$ and $8$). Make sure all the reduced congruences agree (otherwise you have no solution), and then keep only the highest power one for each prime. – Yoni Rozenshein Mar 25 '13 at 15:30
  • So in other words if I have x = a mod m, it is the same as x = a-gcd(a,m) mod m-gcd(a,m)? – user2175923 Mar 25 '13 at 15:31
  • No, that doesn't sound right. I'm saying that $x \equiv a \pmod {mm'}$ can be reduced to $x \equiv a \pmod m$. For example, $x \equiv 3 \pmod 6$ can be reduced to $x \equiv 3 \equiv 1 \pmod 2$ and $x \equiv 3 \equiv 0 \pmod 3$. – Yoni Rozenshein Mar 25 '13 at 15:33
  • In other words you are trying to reduce it until the modulus is a prime number? I am trying to understand the general algorithm here. If I give you x = a mod m and x = b mod n, where m and n aren't coprime, what is the strategy? We know L = lcm(m,n) and you are saying work through the primes of L somehow? Work how? – user2175923 Mar 25 '13 at 15:38
  • Yep, see my first comment in this thread. – Yoni Rozenshein Mar 25 '13 at 15:38
  • I am saying I don't understand what that means, "work through all primes p" and then reduce to highest power. 24 = primes 2 and 3 – user2175923 Mar 25 '13 at 15:44
  • And if I reduce the first one to mod 2 then it's not coprime to 8 still – user2175923 Mar 25 '13 at 16:02
  • 8 plays the role of "the highest power of 2". – Yoni Rozenshein Mar 25 '13 at 19:01
0

Hint $\rm\,\ 6,8\mid x\!+\!3\iff lcm(6,8)=24\mid x\!+\!3\iff mod\ 24\!:\ x\equiv -3\equiv 21.\ \ $ QED

Remark $\ $ It has easy solution since the system is equivalent to a constant case of CRT, viz. $\rm\:x\equiv 3\equiv \color{#C00}{-3}\pmod 6\:$ and $\rm\: x\equiv 5\equiv \color{#C00}{-3}\pmod 8,\:$ so $\rm\:x\equiv \color{#C00}{-3}\:$ both $\rm\:mod\ 6\:$ and $\rm\:mod\ 8.\:$ Therefore, as above, we deduce that $\rm\:x\equiv \color{#C00}{-3}\pmod{24},\ $ since $\rm\: 24 = lcm(6,8).\ $ Generally we have

$$\rm\:\begin{eqnarray}x&\equiv&\rm c\ \ (mod\ m)\\ \rm x&\equiv&\rm c\ \ (mod\ n)\end{eqnarray}\iff m,n\mid x\!-\!c\iff lcm(m,n)\mid x\!-\!c\iff x\equiv c\ \ (mod\ lcm(m,n))$$

Math Gems
  • 19,574
  • What is x+3 here? – user2175923 Mar 25 '13 at 15:46
  • $\rm:x:$ is any solution. Note $\rm:mod\ 6!:\ x\equiv 3:\Rightarrow: x+3\equiv 6\equiv 0,:$ and $\rm:mod\ 8!:\ x\equiv 5:\Rightarrow: x+5\equiv 8\equiv 0.$ – Math Gems Mar 25 '13 at 15:50
  • So you're saying that this is the same as solving for -constant + lcm(modulus 1, modulus 2) ? Is this generally true? – user2175923 Mar 25 '13 at 16:10
  • @user2175923 Yes, the constant case of CRT always has such a trivial solution, see the edit to my answer. – Math Gems Mar 25 '13 at 16:19
  • Is this the same as finding X in the system X+k = a mod m and X-k = b mod n for constant k? It's always going to be -k + lcm(m,n)? This doesn't seem to hold true when I test it out in a program (for example I changed k to 7 and it didn't hold) – user2175923 Mar 25 '13 at 16:27
  • The special constant case of CRT is useful only in cases where, as above, one can easily tweak the remainders to have the same value for both moduli. Of course the solution will always be once such constant value, but it may not be so easy to find by a simple tweaking of the remainders (such as adding/subtracting the modulus, as above). – Math Gems Mar 25 '13 at 16:36
  • So I am solving for CRT with remainders k and -k with moduli n and m, correct? – user2175923 Mar 25 '13 at 16:38
  • No, your original problem has remainders $\rm:-k:$ and $\rm -k,:$ for $\rm:k = 3.:$ – Math Gems Mar 25 '13 at 16:41
  • What about the general case k and -k with moduli n and m where n and m are not necessarily coprime (they may or may not be)? – user2175923 Mar 25 '13 at 16:44
  • To clarify, $\rm:x\equiv a\ \ (mod\ m),\ x\equiv b\ \ (mod\ n)\iff a+jm = x = b+kn:$ for some $\rm:j,k\in\Bbb Z.:$ If there are "obvious" solutions $\rm:j,k:$ then this yields $\rm:x.:$ In your original problem there is the obvious solution $\rm:j=-1=k:$ since $\rm: a-m = 3-6 = -3 = 5-8 = b-n.:$ For small moduli, testing small values of $\rm:j,k:$ often quickly yields the solution (law of small numbers). – Math Gems Mar 25 '13 at 16:49
  • But is there a generalized algorithm/strategy for solving such congruences that don't rely on making "obvious" picks of numbers? i.e. if we assume it is not obvious – user2175923 Mar 25 '13 at 16:53
  • The general algorithm is CRT = Chinese Remainder Theorem, e.g. see Easy CRT. Said constant case is a special optimization that proves very handy for manual calculations. – Math Gems Mar 25 '13 at 16:55
  • That is for coprime m and n (I have a program I made a long time using the wiki that correctly solves CRT with m and n coprime); I don't know how to modify it so it can solve for cases with m and n not coprime. In other words I am trying to find some way to reduce not-coprime m and n to a coprime case where I can apply the usual method, unless there's a better way for two variables? – user2175923 Mar 25 '13 at 17:00