Solve $x\equiv 1\pmod2$, $x\equiv 2\pmod3$, $x\equiv 3\pmod4$, $x\equiv 4\pmod5$, $x\equiv 5\pmod6$ and $x\equiv 0\pmod7$

$$\begin{align*} x&\equiv 1\pmod2\\ x&\equiv 2\pmod3\\ x&\equiv 3\pmod4\\ x& \equiv 4\pmod5\\ x&\equiv 5\pmod6\\ x&\equiv 0\pmod7\\ \end{align*}$$

So the solution says we can eliminate $x\equiv 5(\bmod6)$ because the first two cases cover it, but I don't really know how it does. How do we solve it in cases like this where the moduli are not mutually relatively prime.


Since $\,m_i-1\equiv \color{#c00}{-1}\pmod{\!m_i}\,$ we can apply $ $ CCRT = $\rm\color{#c00}{constant}$ case optimization of CRT

$\qquad\qquad\ \ \ \begin{align} x &\equiv \color{#c00}{-1}\!\!\pmod{\!m_1}\\ &\ \ \vdots\\ x &\equiv \color{#c00}{-1}\!\!\pmod{\!m_k}\end{align} \iff\ x\equiv \color{#c00}{-1}\!\!\pmod{{\rm lcm}\{m_1,\ldots,m_k)}$

$\ \ \ \ \ \text{or, without CRT:}\ \ \ {\rm all}\ \ m_i \mid x+1 \iff {\rm lcm}\{{\rm all}\ m_i\}\mid x+1$

The latter equivalence is by the Universal Property of LCM (= definition of LCM in general)

Therefore $\, x\equiv -1\pmod{2,3,4,5,6}\iff x\equiv\color{#0a0}{-1}\pmod{\color{#0a0}{\!60} = {\rm lcm}(2,3,4,5,6})$

So $\bmod 7\!:\,\ 0\equiv x\equiv \color{#0a0}{60k-1}\equiv 4k-1\iff 4k\equiv 1\equiv 8\iff k\equiv 2\iff \color{#90f}{k = 2\!+\!7n}$

Combining yields $\ x = 60\color{#90f}k-1 = 60(\color{#90f}{2\!+\!7n})-1 = 119 + 420n$

Remark $ $ To compute the lcm we can either use prime factorizations or else use distributivity and factor deletion: $\,[a,ab,c,\ldots] = [ab,c,\ldots]\,$ since $\,a,ab\mid m\iff ab\mid m.\,$ Applied to OP

$$[\color{#0a0}2,\color{#c00}3,\color{#0a0}4,5,\color{#c00}6] = [4,5,6] = [5,2[2,3]] = [5,12] = 60\qquad $$

since $\,[a,b] = ab\ $ for $a,b$ coprime (notice we also used associativity and commutativity of lcm).

Generally, for congruence systems with noncoprime moduli we can factor the moduli to split the congruences into an equivalent system with pair-coprime modulu (e.g distinct prime powers) e.g here and here or we can solve it 2 congruences at a time while cancelling common moduli factors.


More generally this idea works for linearly related values & moduli: $ $ if $\,(a,b) = 1\,$ then

$$\left\{\,x\equiv d\!-\!ck\!\!\!\pmod{b\!-\!ak}\,\right\}_{k=0}^{n}\!\!\iff\! x\equiv \dfrac{ad\!-\!bc}a\!\!\!\pmod{{\rm lcm}\{b\!-\!ak\}_{k=0}^n}\quad \ $$

$ $ e.g. here $\,\ \underbrace{\left\{\,x \equiv 3-k\pmod{7-k}\,\right\}_{k=0}^2}_{\textstyle{x\equiv 3,2,1\pmod{\!7,6,5}}}\!\!\iff\! x\equiv \dfrac{1(3)-7(1)}1\equiv -4\pmod{210}$