Skip to content

Linear Congruences

A linear congruence is a congruence of the form

Definition

A linear congruence is a congruence of the form

axb(modn), ax\equiv b\pmod n,

where a,bZa,b\in\mathbb{Z}, nNn\in\mathbb{N}, and xx is the unknown integer.

This congruence means that

n(axb). n\mid(ax-b).

Equivalently, there exists an integer yy such that

axb=ny. ax-b=ny.

Rearranging gives the linear Diophantine equation

axny=b. ax-ny=b.

Thus solving a linear congruence is closely related to solving a linear equation in two integer variables.

First Examples

Consider

3x1(mod7). 3x\equiv1\pmod7.

Testing residues modulo 77, we find

35=151(mod7). 3\cdot5=15\equiv1\pmod7.

So

x5(mod7) x\equiv5\pmod7

is the solution.

Now consider

4x2(mod6). 4x\equiv2\pmod6.

Testing residues modulo 66,

42=82(mod6) 4\cdot2=8\equiv2\pmod6

and

45=202(mod6). 4\cdot5=20\equiv2\pmod6.

Thus there are two residue classes of solutions:

x2(mod6),x5(mod6). x\equiv2\pmod6, \qquad x\equiv5\pmod6.

A linear congruence may therefore have no solution, one solution modulo nn, or several solutions modulo nn.

Solvability Criterion

The congruence

axb(modn) ax\equiv b\pmod n

has an integer solution if and only if

gcd(a,n)b. \gcd(a,n)\mid b.

Let

d=gcd(a,n). d=\gcd(a,n).

If xx is a solution, then

axb(modn), ax\equiv b\pmod n,

so

axb=ny ax-b=ny

for some integer yy. Hence

b=axny. b=ax-ny.

Since dad\mid a and dnd\mid n, it follows that

db. d\mid b.

Conversely, if dbd\mid b, Bezout’s identity gives integers u,vu,v such that

au+nv=d. au+nv=d.

Multiplying by b/db/d, we obtain

a(ubd)+n(vbd)=b. a\left(u\frac bd\right)+n\left(v\frac bd\right)=b.

Thus

a(ubd)b(modn). a\left(u\frac bd\right)\equiv b\pmod n.

So the congruence has a solution.

The Coprime Case

The simplest case occurs when

gcd(a,n)=1. \gcd(a,n)=1.

Then the congruence

axb(modn) ax\equiv b\pmod n

has a unique solution modulo nn.

Since gcd(a,n)=1\gcd(a,n)=1, the integer aa has a multiplicative inverse modulo nn. Let this inverse be a1a^{-1}. Multiplying both sides by a1a^{-1}, we get

xa1b(modn). x\equiv a^{-1}b\pmod n.

For example, solve

5x3(mod11). 5x\equiv3\pmod{11}.

Since

59=451(mod11), 5\cdot9=45\equiv1\pmod{11},

the inverse of 55 modulo 1111 is 99. Therefore

x93=275(mod11). x\equiv9\cdot3=27\equiv5\pmod{11}.

So the solution is

x5(mod11). x\equiv5\pmod{11}.

The General Case

Let

d=gcd(a,n). d=\gcd(a,n).

If

db, d\nmid b,

then

axb(modn) ax\equiv b\pmod n

has no solution.

If

db, d\mid b,

divide the congruence by dd. Write

a=da,b=db,n=dn. a=da', \qquad b=db', \qquad n=dn'.

Then

daxdb(moddn). da'x\equiv db'\pmod{dn'}.

This is equivalent to

axb(modn). a'x\equiv b'\pmod{n'}.

Now

gcd(a,n)=1, \gcd(a',n')=1,

so the reduced congruence has a unique solution modulo nn'. This gives dd distinct solutions modulo nn.

Example of the General Case

Solve

6x9(mod15). 6x\equiv9\pmod{15}.

We compute

d=gcd(6,15)=3. d=\gcd(6,15)=3.

Since

39, 3\mid9,

solutions exist.

Divide by 33:

2x3(mod5). 2x\equiv3\pmod5.

The inverse of 22 modulo 55 is 33, because

23=61(mod5). 2\cdot3=6\equiv1\pmod5.

Thus

x33=94(mod5). x\equiv3\cdot3=9\equiv4\pmod5.

Modulo 1515, this gives three solutions:

x4,9,14(mod15). x\equiv4,9,14\pmod{15}.

Indeed,

64=249(mod15), 6\cdot4=24\equiv9\pmod{15}, 69=549(mod15), 6\cdot9=54\equiv9\pmod{15},

and

614=849(mod15). 6\cdot14=84\equiv9\pmod{15}.

Number of Solutions

For the congruence

axb(modn), ax\equiv b\pmod n,

let

d=gcd(a,n). d=\gcd(a,n).

If dbd\nmid b, there are no solutions modulo nn.

If dbd\mid b, there are exactly dd incongruent solutions modulo nn.

These solutions are separated by

nd. \frac nd.

If x0x_0 is one solution to the reduced congruence modulo n/dn/d, then the full set of solutions modulo nn is

xx0+knd(modn),k=0,1,,d1. x\equiv x_0+k\frac nd\pmod n, \qquad k=0,1,\ldots,d-1.

Role in Number Theory

Linear congruences are the first equations of modular arithmetic. They connect divisibility, greatest common divisors, Bezout identities, and modular inverses.

They are used in solving Diophantine equations, constructing modular inverses, proving the Chinese remainder theorem, analyzing periodic sequences, and building cryptographic algorithms.

The key principle is simple: the congruence

axb(modn) ax\equiv b\pmod n

is solvable exactly when the common divisor structure of aa and nn is compatible with bb.