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 ‘‘xcmodnx\equiv c\bmod n’’ for some nn\in\mathbb{N}. A congruence x+abmodmx+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 xb-amodmx\equiv b-a\bmod m.

A congruence axbmodmax\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)

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

  2. (ii)

    6x9mod156x\equiv 9\bmod 15 has both x=4x=4 and x=9x=9 as solutions (as 64=24=115+96\cdot 4=24=1\cdot 15+9 and 69=54=315+96\cdot 9=54=3\cdot 15+9); since 49mod154\not\equiv 9\bmod 15, the solution cannot be of the form ‘‘xcmod15x\equiv c\bmod 15’’.

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

Theorem 5.2.2

Let a,ba,b\in\mathbb{Z} and mm\in\mathbb{N}. The congruence axbmodmax\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 6x4mod106x\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 6x4mod96x\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 xx\in\mathbb{Z}, so that axbmodmax\equiv b\bmod m. We can then write ax=qm+bax=qm+b for some qq\in\mathbb{Z}, and thus b=ax-qmb=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=tdb=td for some tt\in\mathbb{Z}. By Theorem 4.2.17, we can write d=ra+smd=ra+sm for some r,sr,s\in\mathbb{Z}, and therefore

b=td=t(ra+sm)=a(tr)+(ts)ma(tr)modm;b=td=t(ra+sm)=a(tr)+(ts)m\equiv a(tr)\bmod m;

so the congruence has solutions, because x=trx=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,ba,b\in\mathbb{Z} and mm\in\mathbb{N} satisfy hcf(a,m)|b\mathrm{hcf}(a,m)|b, and choose r,sr,s\in\mathbb{Z} such that hcf(a,m)=ra+sm\mathrm{hcf}(a,m)=ra+sm. Then x=br/hcf(a,m)x=br/\mathrm{hcf}(a,m) is a solution to the congruence axbmodmax\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,cb,c\in\mathbb{Z} and mm\in\mathbb{N}, and suppose that aa and mm are coprime. If abacmodmab\equiv ac\bmod m, then bcmodmb\equiv c\bmod m.

Proof. By assumption, mm divides ab-ac=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\}, bb\in\mathbb{Z} and mm\in\mathbb{N}, and suppose that aa and mm are coprime. Then there are r,sr,s\in\mathbb{Z} such that 1=ra+sm1=ra+sm, and the complete solution to the congruence axbmodmax\equiv b\bmod m is given by xbrmodmx\equiv br\bmod m.

Example 5.2.7

Consider the congruence 6x14mod296x\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=56+(-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

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

(We can easily check that 7070 is a solution: 670-14=406=14296\cdot 70-14=406=14\cdot 29.) Since 70=229+1270=2\cdot 29+12, we can (and should!) simplify this answer to x12mod29x\equiv 12\bmod 29.

Proof. Set c=brc=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, acbmodmac\equiv b\bmod m.

We must show that an integer xx satisfies axbmodmax\equiv b\bmod m if and only if xcmodmx\equiv c\bmod m.

‘‘\Rightarrow’’. Suppose that axbmodmax\equiv b\bmod m. Lemma 5.1.7 shows that bacmodmb\equiv ac\bmod m, so that axacmodmax\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 xcmodmx\equiv c\bmod m.

‘‘\Leftarrow’’. Suppose that xcmodmx\equiv c\bmod m. By Lemma 5.1.7, we have axacmodmax\equiv ac\bmod m. Since acbmodmac\equiv b\bmod m, Lemma 5.1.9 implies that axbmodmax\equiv b\bmod m. \Box

We can now solve completely any congruence of the form axbmodmax\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,ba,b\in\mathbb{Z} and d,nd,n\in\mathbb{N}. Then adbdmodndad\equiv bd\bmod nd if and only if abmodna\equiv b\bmod n.

Proof. By Proposition 5.1.3(b), adbdmodndad\equiv bd\bmod nd means that ad=qnd+bdad=qnd+bd for some qq\in\mathbb{Z}, while abmodna\equiv b\bmod n means that a=qn+ba=qn+b for some q.q\in\mathbb{Z}. These two statements are clearly equivalent (divide/multiply by d0d\neq 0). \Box

Example 5.2.9

Decide whether or not the congruence 30x70mod14530x\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 30x70mod14530x\equiv 70\bmod 145 if and only if

305x705mod1455,  that is,  6x14mod29;\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 x12mod29.x\equiv 12\bmod 29.

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

3012-70=290=2145.30\cdot 12-70=290=2\cdot 145.
Example 5.2.10

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

Solution. By the Euclidean algorithm, we find

164\displaystyle 164 =626+8\displaystyle=6\cdot 26+8 and 2\displaystyle 2 =26-38\displaystyle=26-3\cdot 8
26\displaystyle 26 =38+2\displaystyle=3\cdot 8+2 =26-3(164-626)\displaystyle=26-3(164-6\cdot 26)
8\displaystyle 8 =42+0,\displaystyle=4\cdot 2+0, =1926-3164.\displaystyle=19\cdot 26-3\cdot 164.
so thathcf(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 26x74mod16426x\equiv 74\bmod 164 if and only if

262x742mod1642,  that is,  13x37mod82,\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=1926-31642=1913-382,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

x3719=703882+4747mod82,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:

2647-74=1148=7164.26\cdot 47-74=1148=7\cdot 164.