Home page for accesible maths 5 Congruences

Style control - access keys in brackets

Font (2 3) - + Letter spacing (4 5) - + Word spacing (6 7) - + Line spacing (8 9) - +

5.2 Solving linear congruences

If a congruence involves an unknown xx, we can try to solve it, just like an equation — but there will never be a unique solution, as multiples of the modulus may always be added without changing anything; the best we can hope for is to express the solution in the form ‘‘x≡cmodnx\equiv c\bmod n’’ for some n∈ℕn\in\mathbb{N}. A congruence x+a≡bmodmx+a\equiv b\bmod m is easy: adding -a-a to both sides (as we may by Lemma 5.1.7) gives the solution as x≡b-amodmx\equiv b-a\bmod m.

A congruence a⁢x≡bmodmax\equiv b\bmod m is more subtle, however: there may be no solutions at all; or if there are any, they may involve a modulus other than mm.

Example 5.2.1
  1. (i)

    4⁢x≡3mod104x\equiv 3\bmod 10 has no solutions, since any number 4⁢x4x is even, whereas any number congruent to 33 modulo 1010 is odd.

  2. (ii)

    6⁢x≡9mod156x\equiv 9\bmod 15 has both x=4x=4 and x=9x=9 as solutions (as 6⋅4=24=1⋅15+96\cdot 4=24=1\cdot 15+9 and 6⋅9=54=3⋅15+96\cdot 9=54=3\cdot 15+9); since 4≢9mod154\not\equiv 9\bmod 15, the solution cannot be of the form ‘‘x≡cmod15x\equiv c\bmod 15’’.

Example 5.2.1(i) raises the question: when does the congruence a⁢x≡bmodmax\equiv b\bmod m have solutions? The answer is as follows.

Theorem 5.2.2

Let a,b∈ℤa,b\in\mathbb{Z} and m∈ℕm\in\mathbb{N}. The congruence a⁢x≡bmodmax\equiv b\bmod m has solutions if and only if hcf(a,m)|b\mathrm{hcf}(a,m)|b.

Example 5.2.3

The congruence 6⁢x≡4mod106x\equiv 4\bmod 10 has solutions because hcf⁢(6,10)=2\mathrm{hcf}(6,10)=2 and 2|42|4 (in fact x=4x=4 is one solution). On the other hand, the congruence 6⁢x≡4mod96x\equiv 4\bmod 9 does not have any solutions because hcf⁢(6,9)=3\mathrm{hcf}(6,9)=3 and 3| 4.3\!\!\!\!\;\not\!\!\!\;|\!\;4.

Proof. Set d=hcf⁢(a,m)d=\mathrm{hcf}(a,m).

‘‘⇒\Rightarrow’’. Suppose that the congruence has solutions; choose one, say x∈ℤx\in\mathbb{Z}, so that a⁢x≡bmodmax\equiv b\bmod m. We can then write a⁢x=q⁢m+bax=qm+b for some q∈ℤq\in\mathbb{Z}, and thus b=a⁢x-q⁢mb=ax-qm. Since d|ad|a and d|md|m, we conclude that d|b.d|b.

‘‘⇐\Leftarrow’’. Conversely, suppose that d|bd|b, say b=t⁢db=td for some t∈ℤt\in\mathbb{Z}. By Theorem 4.2.17, we can write d=r⁢a+s⁢md=ra+sm for some r,s∈ℤr,s\in\mathbb{Z}, and therefore

b=t⁢d=t⁢(r⁢a+s⁢m)=a⁢(t⁢r)+(t⁢s)⁢m≡a⁢(t⁢r)modm;b=td=t(ra+sm)=a(tr)+(ts)m\equiv a(tr)\bmod m;

so the congruence has solutions, because x=t⁢rx=tr is one. □\Box

In fact the second half of the proof of Theorem 5.2.2 gives us more than we have stated: whenever solutions exist, it tells us how to find one explicitly. We formally record this finding as follows.

Corollary 5.2.4

Suppose that a,b∈ℤa,b\in\mathbb{Z} and m∈ℕm\in\mathbb{N} satisfy hcf(a,m)|b\mathrm{hcf}(a,m)|b, and choose r,s∈ℤr,s\in\mathbb{Z} such that hcf⁢(a,m)=r⁢a+s⁢m\mathrm{hcf}(a,m)=ra+sm. Then x=b⁢r/hcf⁢(a,m)x=br/\mathrm{hcf}(a,m) is a solution to the congruence a⁢x≡bmodmax\equiv b\bmod m.

We now turn our attention to the problem of finding all solutions to a given congruence (under the assumption that solutions exist, of course). We refer to this as finding the complete solution to the congruence. In this context, a specific number which satisfies the congruence is called a particular solution.

We begin by considering the case where aa and mm are coprime.

Lemma 5.2.5

Let a∈ℤ∖{0}a\in\mathbb{Z}\setminus\{0\}, b,c∈ℤb,c\in\mathbb{Z} and m∈ℕm\in\mathbb{N}, and suppose that aa and mm are coprime. If a⁢b≡a⁢cmodmab\equiv ac\bmod m, then b≡cmodmb\equiv c\bmod m.

Proof. By assumption, mm divides a⁢b-a⁢c=a⁢(b-c)ab-ac=a(b-c). As aa and mm are coprime, this implies that mm divides b-cb-c by Theorem 4.4.8, and the result follows. □\Box

Theorem 5.2.6

Let a∈ℤ∖{0}a\in\mathbb{Z}\setminus\{0\}, b∈ℤb\in\mathbb{Z} and m∈ℕm\in\mathbb{N}, and suppose that aa and mm are coprime. Then there are r,s∈ℤr,s\in\mathbb{Z} such that 1=r⁢a+s⁢m1=ra+sm, and the complete solution to the congruence a⁢x≡bmodmax\equiv b\bmod m is given by x≡b⁢rmodmx\equiv br\bmod m.

Example 5.2.7

Consider the congruence 6⁢x≡14mod296x\equiv 14\bmod 29; in the notation of Theorem 5.2.6, we have a=6a=6, b=14b=14 and m=29m=29. Prime factorization shows that 66 and 2929 are coprime, so that hcf⁢(a,m)\mathrm{hcf}(a,m) divides bb, and therefore solutions exist. It is easy to see that 1=5⋅6+(-1)⁢291=5\cdot 6+(-1)29 (if not, use the Euclidean algorithm!), so that we can choose r=5r=5 and s=-1s=-1. Hence we conclude that the congruence has the complete solution

x≡14⋅5=70mod29.x\equiv 14\cdot 5=70\bmod 29.

(We can easily check that 7070 is a solution: 6⋅70-14=406=14⋅296\cdot 70-14=406=14\cdot 29.) Since 70=2⋅29+1270=2\cdot 29+12, we can (and should!) simplify this answer to x≡12mod29x\equiv 12\bmod 29.

Proof. Set c=b⁢r∈ℤc=br\in\mathbb{Z}. Since aa and mm are coprime, Corollary 5.2.4 shows that x=cx=c is a solution to the congruence, that is, a⁢c≡bmodmac\equiv b\bmod m.

We must show that an integer xx satisfies a⁢x≡bmodmax\equiv b\bmod m if and only if x≡cmodmx\equiv c\bmod m.

‘‘⇒\Rightarrow’’. Suppose that a⁢x≡bmodmax\equiv b\bmod m. Lemma 5.1.7 shows that b≡a⁢cmodmb\equiv ac\bmod m, so that a⁢x≡a⁢cmodmax\equiv ac\bmod m by Lemma 5.1.9. Lemma 5.2.5 allows us to cancel aa because aa and mm are coprime, and hence we have x≡cmodmx\equiv c\bmod m.

‘‘⇐\Leftarrow’’. Suppose that x≡cmodmx\equiv c\bmod m. By Lemma 5.1.7, we have a⁢x≡a⁢cmodmax\equiv ac\bmod m. Since a⁢c≡bmodmac\equiv b\bmod m, Lemma 5.1.9 implies that a⁢x≡bmodmax\equiv b\bmod m. □\Box

We can now solve completely any congruence of the form a⁢x≡bmodmax\equiv b\bmod m provided that aa and mm are coprime. Thus all that remains is to show how to reduce a general congruence which has solutions to one in which aa and mm are coprime. This is easily achieved using the following result.

Lemma 5.2.8

Suppose that a,b∈ℤa,b\in\mathbb{Z} and d,n∈ℕd,n\in\mathbb{N}. Then a⁢d≡b⁢dmodn⁢dad\equiv bd\bmod nd if and only if a≡bmodna\equiv b\bmod n.

Proof. By Proposition 5.1.3(b), a⁢d≡b⁢dmodn⁢dad\equiv bd\bmod nd means that a⁢d=q⁢n⁢d+b⁢dad=qnd+bd for some q∈ℤq\in\mathbb{Z}, while a≡bmodna\equiv b\bmod n means that a=q⁢n+ba=qn+b for some q∈ℤ.q\in\mathbb{Z}. These two statements are clearly equivalent (divide/multiply by d≠0d\neq 0). □\Box

Example 5.2.9

Decide whether or not the congruence 30⁢x≡70mod14530x\equiv 70\bmod 145 has solutions; if solutions exist, find the complete solution.

Solution. By prime factorization (or the Euclidean algorithm), we find hcf⁢(30,145)=5\mathrm{hcf}(30,145)=5. Since 5|705|70, solutions exist by Theorem 5.2.2. To find the complete solution, we apply Lemma 5.2.8: an integer xx satisfies 30⁢x≡70mod14530x\equiv 70\bmod 145 if and only if

305⁢x≡705mod1455,  that is,  6⁢x≡14mod29;\frac{30}{5}x\equiv\frac{70}{5}\bmod\frac{145}{5},\qquad\text{that is,}\qquad 6% x\equiv 14\bmod 29;

we saw above that this congruence has the complete solution x≡12mod29.x\equiv 12\bmod 29.

As a check, we verify that x=12x=12 satisfies the original congruence:

30⋅12-70=290=2⋅145.30\cdot 12-70=290=2\cdot 145.
Example 5.2.10

Decide whether or not the congruence 26⁢x≡74mod16426x\equiv 74\bmod 164 has solutions; if solutions exist, find the complete solution.

Solution. By the Euclidean algorithm, we find

164\displaystyle 164 =6⋅26+8\displaystyle=6\cdot 26+8 and 2\displaystyle 2 =26-3⋅8\displaystyle=26-3\cdot 8
26\displaystyle 26 =3⋅8+2\displaystyle=3\cdot 8+2 =26-3⁢(164-6⋅26)\displaystyle=26-3(164-6\cdot 26)
8\displaystyle 8 =4⋅2+0,\displaystyle=4\cdot 2+0, =19⋅26-3⋅164.\displaystyle=19\cdot 26-3\cdot 164.
so that⁢hcf⁢(26,164)\displaystyle\text{so that}\ \mathrm{hcf}(26,164) =2\displaystyle=2

Since 2|742|74, solutions exist by Theorem 5.2.2. To find the complete solution, we apply Lemma 5.2.8: an integer xx satisfies 26⁢x≡74mod16426x\equiv 74\bmod 164 if and only if

262⁢x≡742mod1642,  that is,  13⁢x≡37mod82,\frac{26}{2}x\equiv\frac{74}{2}\bmod\frac{164}{2},\qquad\text{that is,}\qquad 1% 3x\equiv 37\bmod 82, (5.2.1)

where

1=19⋅26-3⋅1642=19⋅13-3⋅82,1=\frac{19\cdot 26-3\cdot 164}{2}=19\cdot 13-3\cdot 82,

so in particular 1313 and 8282 are coprime (but we know that already, by Corollary 4.4.6). Hence the complete solution to the right-hand congruence in (5.2.1) is given by

x≡37⋅19=703≡8⋅82+47≡47mod82,x\equiv 37\cdot 19=703\equiv 8\cdot 82+47\equiv 47\bmod 82,

As a check, we verify that x=47x=47 solves the original congruence:

26⋅47-74=1148=7⋅164.26\cdot 47-74=1148=7\cdot 164.