1.2.2. Linear congruences

This section is based on part of [BUR11, Sec. 4.4].

Definition 1.2.2.1.

Let n≥1{n\geq 1} be an integer. A linear congruence (in one indeterminate) is an equation of the form

a⁢x≡b(modn),ax\equiv b\pmod{n},

where a,b∈ℤ{a,b\in\mathbb{Z}} and xx is an indeterminate. An integer kk is a solution to the linear congruence if a⁢k≡b(modn){ak\equiv b\pmod{n}}. These definitions extend to several indeterminates in the natural way.

The following theorem is a variant of Theorem 1.1.3.23.

Theorem 1.2.2.2.

Let n≥1{n\geq 1} be an integer and a,b∈ℤ{a,b\in\mathbb{Z}}. Consider the linear congruence

a⁢x≡b(modn),ax\equiv b\pmod{n}, (1.2.2.3)

where xx is an indeterminate. Set d≔gcd⁡(a,n){d\coloneqq\gcd(a,n)} so that in particular n/d∈ℤ{n/d\in\mathbb{Z}}. The following statements hold:

  1. (1)
    ​

    The linear congruence (1.2.2.3) admits a solution if and only if d∣b{d\mid b}.

  2. (2)
    ​

    Suppose that d∣b{d\mid b} and let x0∈ℤ{x_{0}\in\mathbb{Z}} be a solution to the linear congruence (1.2.2.3). The following statements hold:

    1. (a)
      ​

      The integers

      x0,x0+nd,x0+2⋅nd,…,x0+(d−1)⋅ndx_{0},\ x_{0}+\frac{n}{d},\ x_{0}+2\cdot\frac{n}{d},\ \ldots,\ x_{0}+(d-1)% \cdot\frac{n}{d}

      are pairwise non-congruent modulo nn.

    2. (b)
      ​

      An integer kk is a solution to the linear congruence (1.2.2.3) if and only if there exists an integer 0≤r<d{0\leq r<d} such that

      k≡x0+r⋅nd(modn).k\equiv x_{0}+r\cdot\frac{n}{d}\pmod{n}.
Proof.

We make the following observation: the linear congruence (1.2.2.3) is equivalent to the linear Diophantine equation a⁢x−n⁢y=b{ax-ny=b}. Indeed, an integer kk is a solution to the linear congruence (1.2.2.3) if and only if there exists ℓ∈ℤ{\ell\in\mathbb{Z}} such that a⁢k−b=ℓ⁢n{ak-b=\ell n} or, equivalently, a⁢k−n⁢ℓ=b{ak-n\ell=b}.

(1) Immediate from Theorem 1.1.3.23.

(2a) Let 0≤s,t<d{0\leq s,t<d} be integers such that

x0+s⋅nd≡x0+t⋅nd(modn).x_{0}+s\cdot\frac{n}{d}\equiv x_{0}+t\cdot\frac{n}{d}\pmod{n}.

By Proposition 1.2.1.6(4), we have

s⋅nd≡t⋅nd(modn).s\cdot\frac{n}{d}\equiv t\cdot\frac{n}{d}\pmod{n}.

Since nd∣n{\frac{n}{d}\mid n}, we have gcd⁡(nd,n)=nd{\gcd(\frac{n}{d},n)=\frac{n}{d}}. Since d=n/(n/d){d=n/(n/d)}, Proposition 1.2.1.8 yields

s≡t(modd).s\equiv t\pmod{d}.

Since 0≤|t−s|<d{0\leq|t-s|<d}, Proposition 1.2.1.2 implies that s=t{s=t}. This proves the claim.

(2b) Recall that a⁢x0≡b(modn){ax_{0}\equiv b{\pmod{n}}} by assumption. For t∈ℤ{t\in\mathbb{Z}} the integer x0+t⋅nd{x_{0}+t\cdot\frac{n}{d}} is a solution to the linear congruence (1.2.2.3):

a⁢(x0+t⋅nd)=a⁢x0+(t⋅ad)⋅na\Big{(}x_{0}+t\cdot\frac{n}{d}\Big{)}=ax_{0}+\Big{(}t\cdot\frac{a}{d}\Big{)}\cdot n

and therefore a⁢(x0+t⋅nd)≡a⁢x0(modn){a(x_{0}+t\cdot\frac{n}{d})\equiv ax_{0}{\pmod{n}}}; here, we use that ad∈ℤ{\tfrac{a}{d}\in\mathbb{Z}} since d=gcd⁡(a,n){d=\gcd(a,n)}. Using again Theorem 1.1.3.23, we only need to prove the following: for every t∈ℤ{t\in\mathbb{Z}} there exists an integer 0≤r<d{0\leq r<d} such that

x0+t⋅nd≡x0+r⋅nd(modn).x_{0}+t\cdot\frac{n}{d}\equiv x_{0}+r\cdot\frac{n}{d}\pmod{n}.

By the Division with Remainder Theorem (Theorem 1.1.1.8), we may write t=k⁢d+r{t=kd+r} with k,r∈ℤ{k,r\in\mathbb{Z}} and 0≤r<d{0\leq r<d}. Then

(x0+t⋅nd)−(x0+r⋅nd)=(k⁢d+r⏟=t)⋅nd−r⋅nd=k⁢n\Big{(}x_{0}+t\cdot\frac{n}{d}\Big{)}-\Big{(}x_{0}+r\cdot\frac{n}{d}\Big{)}=(% \underbrace{kd+r}_{=t})\cdot\frac{n}{d}-r\cdot\frac{n}{d}=kn

is a multiple of nn, as required (alternatively, one can apply Proposition 1.2.1.8 to the congruence t≡r(modd){t\equiv r{\pmod{d}}} using that gcd⁡(nd,n)=nd{\gcd(\tfrac{n}{d},n)=\tfrac{n}{d}}). Conversely, suppose that k∈ℤ{k\in\mathbb{Z}} satisfies

k≡x0+r⋅nd(modn)k\equiv x_{0}+r\cdot\frac{n}{d}{\pmod{n}}

for some 0≤r<d{0\leq r<d}. By Proposition 1.2.1.6(4), we have a⁢k≡b(modn){ak\equiv b{\pmod{n}}} since x0+r⋅nd{x_{0}+r\cdot\tfrac{n}{d}} is a solution to the linear congruence (1.2.2.3), as shown above. This finishes the proof. ∎

We list some important corollaries of Theorem 1.2.2.2.

Corollary 1.2.2.4.

Let n≥1{n\geq 1} be an integer and a,b∈ℤ{a,b\in\mathbb{Z}}. Set d≔gcd⁡(a,n){d\coloneqq\gcd(a,n)}. The linear congruence a⁢x≡b(modn){ax\equiv b\pmod{n}} admits an integer solution if and only if d∣b{d\mid b}. In this case, there are exactly dd pairwise non-congruent solutions modulo nn.

Proof.

Immediate from Theorem 1.2.2.2. ∎

Corollary 1.2.2.5.

Not covered in the lecture Let n≥1{n\geq 1} be an integer and a,b∈ℤ{a,b\in\mathbb{Z}}. If gcd⁡(a,n)=1{\gcd(a,n)=1}, then the linear congruence a⁢x≡b(modn){ax\equiv b\pmod{n}} admits a unique integer solution modulo nn.

Proof.

Immediate from Corollary 1.2.2.4. ∎

Corollary 1.2.2.6.

Not covered in the lecture Let pp be a prime. Let a,b∈ℤ{a,b\in\mathbb{Z}} be such that p∤a{p\nmid a}. The linear congruence a⁢x≡b(modp){ax\equiv b\pmod{p}} admits a unique integer solution modulo pp.

Proof.

The assumption p∤a{p\nmid a} implies that gcd⁡(a,p)=1{\gcd(a,p)=1}. The claim is now immediate from Corollary 1.2.2.5. ∎

Corollary 1.2.2.7.

Not covered in the lecture Let pp be a prime and let a∈ℤ{a\in\mathbb{Z}}. The linear congruence

a⁢x≡1(modp)ax\equiv 1\pmod{p}

admits an integer solution if and only if p∤a{p\nmid a}. In this case, the solution is unique modulo pp.

Proof.

If p∣a{p\mid a}, then a⁢x≡0(modp){ax\equiv 0\pmod{p}} and the congruence 0≡1(modp){0\equiv 1\pmod{p}} is false. If p∤a{p\nmid a}, then the claims are immediate from Corollary 1.2.2.6. ∎

Remark 1.2.2.8.

Not covered in the lecture Let n≥1{n\geq 1} be an integer and a,b∈ℤ{a,b\in\mathbb{Z}} with gcd⁡(a,n)=1{\gcd(a,n)=1}. Consider the congruence

a⁢x≡b(modn).ax\equiv b{\pmod{n}}.

Recall that we consider its solutions modulo nn. The unique solution to this congruence (Corollary 1.2.2.5) can be computed algorithmically as follows:

  1. (1)
    ​

    Compute a pair of Bézout coefficients u,v∈ℤ{u,v\in\mathbb{Z}} such that 1=a⁢u+n⁢v{1=au+nv}, for example using the procedure in the proof of Bézout’s Identity (Theorem 1.1.3.7).

  2. (2)
    ​

    Since a⁢u≡1(modn){au\equiv 1{\pmod{n}}}, the integer x0≔u⁢b{x_{0}\coloneqq ub} satisfies a⁢x0=a⁢u⁢b{ax_{0}=aub} and hence

    a⁢x0≡b(modn).ax_{0}\equiv b{\pmod{n}}.
Example 1.2.2.9.

Not covered in the lecture Let a=6{a=6}, b=5{b=5}, and n=13{n=13}. We have gcd⁡(6,13)=1{\gcd(6,13)=1}. Consider the linear congruence

6⁢x≡5(mod13).6x\equiv 5{\pmod{13}}.

We compute Bézout coefficients for gcd⁡(13,6)=gcd⁡(6,13){\gcd(13,6)=\gcd(6,13)} using the Extended Euclidean Algorithm (Theorem 1.1.3.6) (or by direct inspection):

x−1\displaystyle x_{-1} =1,\displaystyle=1, y−1\displaystyle y_{-1} =0\displaystyle=0
x0\displaystyle x_{0} =0,\displaystyle=0, y0\displaystyle y_{0} =1\displaystyle=1
13\displaystyle 13 =2⋅6+1,\displaystyle=2\cdot 6+1, q1\displaystyle q_{1} =2,\displaystyle=2, x1\displaystyle x_{1} =1,\displaystyle=1, y1\displaystyle y_{1} =−2\displaystyle=-2
6\displaystyle 6 =6⋅1.\displaystyle=6\cdot 1.

Indeed, 6⋅(−2)+13⋅1=1{6\cdot(-2)+13\cdot 1=1}. The integer −10=(−2)⋅5{-10=(-2)\cdot 5} is a solution to the congruence, since

(6⋅(−10))−5=−65=13⋅(−5)(6\cdot(-10))-5=-65=13\cdot(-5)

is divisible by 1313.

End of Lecture 6

The following theorem, and its proof, reminds us of the procedure for solving a system of linear equations studied in the Linear Algebra course.

Theorem 1.2.2.10.

Let n≥1{n\geq 1} be an integer and a,b,c,d∈ℤ{a,b,c,d\in\mathbb{Z}}. Set D≔a⁢d−b⁢c{D\coloneqq ad-bc} and suppose that gcd⁡(D,n)=1{\gcd(D,n)=1}. For given r,s∈ℤ{r,s\in\mathbb{Z}}, the system of linear congruences

a⁢x+b⁢y≡r(modn),\displaystyle ax+by\equiv r\pmod{n}, (1.2.2.11)
c⁢x+d⁢y≡s(modn),\displaystyle cx+dy\equiv s\pmod{n},

has a unique solution modulo nn. Thus, if (x0,y0)(x_{0},y_{0}) and (x1,y1)(x_{1},y_{1}) are solutions to the system, we must have x0≡x1(modn){x_{0}\equiv x_{1}\pmod{n}} and y0≡y1(modn){y_{0}\equiv y_{1}\pmod{n}}.

Proof.

Since gcd⁡(D,n)=1{\gcd(D,n)=1} by assumption, Corollary 1.2.2.5 implies that the linear congruence

D⁢z≡1(modn)Dz\equiv 1\pmod{n}

admits a unique solution modulo nn. Let t∈ℤ{t\in\mathbb{Z}} be such a solution. We now take a hint from linear algebra: since

(a⁢x+b⁢yc⁢x+d⁢y)=(abcd)⁢(xy),\left(\begin{matrix}ax+by\\ cx+dy\end{matrix}\right)=\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}x\\ y\end{matrix}\right),

the system of linear congruences (1.2.2.11) can be written as

(abcd)⁢(xy)≡(rs)(modn),\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}x\\ y\end{matrix}\right)\equiv\left(\begin{matrix}r\\ s\end{matrix}\right)\pmod{n},

where the congruence is understood coordinate-wise. Observe that

(abcd)⁢(d−b−ca)=D⋅(1001)=(d−b−ca)⁢(abcd).\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}d&-b\\ -c&a\end{matrix}\right)=D\cdot\left(\begin{matrix}1&0\\ 0&1\end{matrix}\right)=\left(\begin{matrix}d&-b\\ -c&a\end{matrix}\right)\left(\begin{matrix}a&b\\ c&d\end{matrix}\right).

Consider the vector

t⋅(d−b−ca)⁢(rs)=(t⁢(d⁢r−b⁢s)t⁢(a⁢s−c⁢r))∈ℤ2.t\cdot\left(\begin{matrix}d&-b\\ -c&a\end{matrix}\right)\left(\begin{matrix}r\\ s\end{matrix}\right)=\left(\begin{matrix}t(dr-bs)\\ t(as-cr)\end{matrix}\right)\in\mathbb{Z}^{2}.

We claim that x0=t⁢(d⁢r−b⁢s){x_{0}=t(dr-bs)} and y0=t⁢(a⁢s−c⁢r){y_{0}=t(as-cr)} give a solution to the system of linear congruences (1.2.2.11). Indeed,

(a⁢x0+b⁢y0c⁢x0+d⁢y0)=(abcd)⁢(x0y0)=t⋅(abcd)⁢(d−b−ca)⁢(rs)=(D⁢t⁢rD⁢t⁢s).\left(\begin{matrix}ax_{0}+by_{0}\\ cx_{0}+dy_{0}\end{matrix}\right)=\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}x_{0}\\ y_{0}\end{matrix}\right)=t\cdot\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}d&-b\\ -c&a\end{matrix}\right)\left(\begin{matrix}r\\ s\end{matrix}\right)=\left(\begin{matrix}Dtr\\ Dts\end{matrix}\right).

Since D⁢t≡1(modn){Dt\equiv 1\pmod{n}}, Proposition 1.2.1.6(4) implies that

D⁢t⁢r≡r(modn)andD⁢t⁢s≡s(modn).Dtr\equiv r\pmod{n}\qquad\text{and}\qquad Dts\equiv s\pmod{n}.

The claim readily follows.

To prove that the solution is unique modulo nn, suppose that x1,y1∈ℤ{x_{1},y_{1}\in\mathbb{Z}} give a solution to the system of linear congruences (1.2.2.11). By definition, there exist k,ℓ∈ℤ{k,\ell\in\mathbb{Z}} such that

(abcd)⁢(x1y1)=(r+n⁢ks+n⁢ℓ).\left(\begin{matrix}a&b\\ c&d\end{matrix}\right)\left(\begin{matrix}x_{1}\\ y_{1}\end{matrix}\right)=\left(\begin{matrix}r+nk\\ s+n\ell\end{matrix}\right).

Multiplying on the left by the matrix (d−b−ca){\left(\begin{smallmatrix}d&-b\\ -c&a\end{smallmatrix}\right)} yields

(D⁢x1D⁢y1)=(d−b−ca)⁢(r+n⁢ks+n⁢ℓ)=((d⁢r−b⁢s)+n⁢k′(a⁢s−c⁢r)+n⁢ℓ′)\left(\begin{matrix}Dx_{1}\\ Dy_{1}\end{matrix}\right)=\left(\begin{matrix}d&-b\\ -c&a\end{matrix}\right)\left(\begin{matrix}r+nk\\ s+n\ell\end{matrix}\right)=\left(\begin{matrix}(dr-bs)+nk^{\prime}\\ (as-cr)+n\ell^{\prime}\end{matrix}\right)

for certain integers k′,ℓ′k^{\prime},\ell^{\prime}. Consequently,

D⁢x1≡d⁢r−b⁢s(modn)andD⁢y1≡a⁢s−c⁢r(modn).Dx_{1}\equiv dr-bs\pmod{n}\qquad\text{and}\qquad Dy_{1}\equiv as-cr\pmod{n}.

Multiplying by tt as above, we obtain

t⁢D⁢x1≡t⁢(d⁢r−b⁢s)(modn)andt⁢D⁢y1≡t⁢(a⁢s−c⁢r)(modn).tDx_{1}\equiv t(dr-bs)\pmod{n}\qquad\text{and}\qquad tDy_{1}\equiv t(as-cr)% \pmod{n}.

Since t⁢D≡1(modn){tD\equiv 1\pmod{n}}, Proposition 1.2.1.6(4) yields the congruences

x1≡t⁢(d⁢r−b⁢s)(modn)andy1≡t⁢(a⁢s−c⁢r)(modn).x_{1}\equiv t(dr-bs)\pmod{n}\qquad\text{and}\qquad y_{1}\equiv t(as-cr)\pmod{n}.

Hence, every solution to the system of linear congruences (1.2.2.11) is congruent coordinate-wise modulo nn to the solution (x0,y0)(x_{0},y_{0}) constructed above. This finishes the proof. ∎

We explain how to use the proof of Theorem 1.2.2.10 to solve an explicit system of linear congruences.

Example 1.2.2.12.

Not covered in the lectureConsider the system of linear congruences

−x+4⁢y≡0(mod14),\displaystyle-x+4y\equiv 0\pmod{14},
2⁢x+3⁢y≡5(mod14).\displaystyle 2x+3y\equiv 5\pmod{14}.

We have

D≔(−1)⋅3−4⋅2=−3−8=−11.D\coloneqq(-1)\cdot 3-4\cdot 2=-3-8=-11.

Notice that gcd⁡(D,14)=gcd⁡(−11,14)=1{\gcd(D,14)=\gcd(-11,14)=1}, and hence the system admits a unique solution modulo 1414 (Theorem 1.2.2.10). We need to solve the linear congruence

D⁢z≡1(mod14).Dz\equiv 1{\pmod{14}}.

We could use the method in Remark 1.2.2.8, but instead we observe that

−11≡3(mod14)-11\equiv 3{\pmod{14}}

and, since 3⋅5=1⋅14+1{3\cdot 5=1\cdot 14+1}, the integer t=5{t=5} is a solution. The solution to the original system of linear congruences is therefore given by the coordinates of the column vector

5⋅(3−4−2−1)⁢(05)=(−100−25).5\cdot\left(\begin{matrix}3&-4\\ -2&-1\end{matrix}\right)\left(\begin{matrix}0\\ 5\end{matrix}\right)=\left(\begin{matrix}-100\\ -25\end{matrix}\right).

Since we are interested in the solutions modulo 1414, we may replace

−100=(−8)⋅14+12-100=(-8)\cdot 14+12

by x0=12{x_{0}=12} and

−25=(−2)⋅14+3-25=(-2)\cdot 14+3

by y0=3{y_{0}=3}. Indeed,

(−1)⋅12+4⋅3\displaystyle(-1)\cdot 12+4\cdot 3 =0,\displaystyle=0,
2⋅12+3⋅3\displaystyle 2\cdot 12+3\cdot 3 =24+9=33≠5,\displaystyle=24+9=33\neq 5,

but 33≡5(mod14){33\equiv 5{\pmod{14}}} since 33=2⋅14+5{33=2\cdot 14+5}.