MathLabs

Grade 9

Linear Diophantine equations

Linear equations for which only integer solutions are sought.

IntuitionIntuition: paying an exact amount with two coin values

Suppose you only have 33-đồng coins and 55-đồng coins and want to pay exactly 88 đồng. You need whole numbers of each coin, so you are really solving 3x+5y=83x+5y=8 for integers x,y≥0x,y\ge 0 — and indeed x=1,y=1x=1,y=1 works since 3+5=83+5=8. The general question "for which integers a,b,ca,b,c does ax+by=cax+by=c have an integer solution, and how do we find all of them?" is the theory of linear Diophantine equations.

A line of slope $-0.6$ and intercept $1.6$, with lattice points marked where it passes through integer coordinates.
The line 3x+5y=83x+5y=8 rewritten as y=−0.6x+1.6y=-0.6x+1.6: integer solutions are exactly the lattice points the line passes through.

SchoolDefinition and the divisibility criterion

Definition: Linear Diophantine equation in two unknowns

An equation ax+by=cax+by=c with integers a,b,ca,b,c and (a,b)≠(0,0)(a,b)\neq(0,0), for which we seek solutions (x,y)(x,y) with x,y∈Zx,y\in\mathbb{Z}, is called a linear Diophantine equation.

ax+by=ca,b,c∈Z, (a,b)≠(0,0)ax+by=c\qquad a,b,c\in\mathbb{Z},\ (a,b)\neq(0,0)

Not every choice of a,b,ca,b,c gives a solvable equation: 2x+4y=72x+4y=7 has none, since the left side is always even. The precise criterion involves d=gcd⁡(a,b)d=\gcd(a,b): the equation has an integer solution if and only if d∣cd \mid c.

d=gcd⁡(a,b)∣c  ⟺  ∃ x,y∈Z: ax+by=cd=\gcd(a,b)\mid c \iff \exists\, x,y\in\mathbb{Z}:\ ax+by=c
Solvability of ax+by=cax+by=c
ConditionSolvable?Solution set
d∣cd \mid cYesInfinite family: x=x0+bdt, y=y0−adtx=x_0+\frac{b}{d}t,\ y=y_0-\frac{a}{d}t
d∤cd \nmid cNoEmpty set ∅\emptyset

AdvancedTheorems and proofs (going beyond the curriculum)

For integers a,ba,b not both 00, there exist integers u,vu,v such that au+bv=gcd⁡(a,b)au+bv=\gcd(a,b).

Why is it true?

It shows the greatest common divisor is not just the "biggest shared factor" but is actually reachable as an integer combination of aa and bb — the key fact that makes the solvability criterion for ax+by=cax+by=c work.

Proof

Consider the set S={au+bv:u,v∈Z}∩Z>0S=\{au+bv : u,v\in\mathbb{Z}\}\cap\mathbb{Z}_{>0} of all strictly positive integer combinations of aa and bb. Since a,ba,b are not both 00, SS is nonempty (it contains ∣a∣|a| or ∣b∣|b|), so by the well-ordering principle SS has a least element d=au0+bv0>0d=au_0+bv_0>0.

We show d∣ad\mid a: divide a=qd+ra=qd+r with 0≤r<d0\le r<d. Then r=a−qd=a−q(au0+bv0)=a(1−qu0)+b(−qv0)r=a-qd=a-q(au_0+bv_0)=a(1-qu_0)+b(-qv_0) is itself an integer combination of a,ba,b. If r>0r>0 then rr would belong to SS and be smaller than dd, contradicting minimality; so r=0r=0, i.e. d∣ad\mid a. The identical argument with bb in place of aa shows d∣bd\mid b.

Since dd is a common divisor of aa and bb, d≤gcd⁡(a,b)d\le \gcd(a,b). Conversely, any common divisor ee of aa and bb divides au0+bv0=dau_0+bv_0=d, so e≤de\le d; taking e=gcd⁡(a,b)e=\gcd(a,b) gives gcd⁡(a,b)≤d\gcd(a,b)\le d.

Combining both inequalities, d=gcd⁡(a,b)d=\gcd(a,b), and by construction d=au0+bv0d=au_0+bv_0, which is exactly Bézout's identity with u=u0,v=v0u=u_0,v=v_0.

ax+by=cax+by=c has an integer solution if and only if d∣cd \mid c where d=gcd⁡(a,b)d=\gcd(a,b); when it does, and (x0,y0)(x_0,y_0) is one solution, every integer solution is exactly x=x0+bdt,  y=y0−adt  (t∈Z)x=x_0+\dfrac{b}{d}t,\ \ y=y_0-\dfrac{a}{d}t\ \ (t\in\mathbb{Z}).

Why is it true?

It completely closes the problem: one divisibility check decides solvability, and once you have any single solution, a one-parameter family via tt hands you every other solution — no guessing required.

Proof

(⇒\Rightarrow) If (x,y)(x,y) is an integer solution, then d=gcd⁡(a,b)d=\gcd(a,b) divides both axax and byby, hence divides ax+by=cax+by=c. So d∣cd \mid c is necessary.

(⇐\Leftarrow) Suppose d∣cd \mid c, say c=dec=de. By Bézout's identity there exist u0,v0u_0,v_0 with au0+bv0=dau_0+bv_0=d. Multiplying by ee gives a(u0e)+b(v0e)=de=ca(u_0e)+b(v_0e)=de=c, so (x0,y0)=(u0e, v0e)(x_0,y_0)=(u_0e,\,v_0e) is an integer solution. This proves solvability.

Now fix any solution (x0,y0)(x_0,y_0) and let (x,y)(x,y) be any other solution. Subtracting ax0+by0=cax_0+by_0=c from ax+by=cax+by=c gives a(x−x0)+b(y−y0)=0a(x-x_0)+b(y-y_0)=0, i.e. a(x−x0)=−b(y−y0)a(x-x_0)=-b(y-y_0). Dividing through by dd: ad(x−x0)=−bd(y−y0)\frac{a}{d}(x-x_0)=-\frac{b}{d}(y-y_0), and since gcd⁡(a/d, b/d)=1\gcd(a/d,\,b/d)=1, the factor bd\frac{b}{d} must divide x−x0x-x_0 (a standard consequence of coprimality: if p∣mnp\mid mn and gcd⁡(p,m)=1\gcd(p,m)=1 then p∣np\mid n). So x−x0=bdtx-x_0=\frac{b}{d}t for some integer tt, and substituting back gives y−y0=−adty-y_0=-\frac{a}{d}t.

Conversely, for any integer tt, substituting x=x0+bdt, y=y0−adtx=x_0+\frac{b}{d}t,\ y=y_0-\frac{a}{d}t into ax+byax+by gives ax0+by0+t(abd−abd)=c+0=cax_0+by_0+t\left(\frac{ab}{d}-\frac{ab}{d}\right)=c+0=c, confirming every such pair is indeed a solution. Hence the solution set is exactly x=x0+bdt,  y=y0−adt  (t∈Z)x=x_0+\dfrac{b}{d}t,\ \ y=y_0-\dfrac{a}{d}t\ \ (t\in\mathbb{Z}).

AdvancedReal-World Applications and Worked Examples

Solving ax+by=cax+by=c is not just a classroom exercise: the extended Euclidean algorithm that produces the Bézout coefficients is exactly what finds a modular inverse in RSA key generation, and the same lattice-point reasoning underlies how computer graphics algorithms (like Bresenham's line drawing) decide which integer pixels a line passes through.

Example: Solving 3x+5y=83x+5y=8 completely

Find all integer solutions of 3x+5y=83x+5y=8, and the one with the smallest nonnegative xx.

Solution

Run the Euclidean algorithm: 5=1⋅3+25=1\cdot 3+2, 3=1⋅2+13=1\cdot 2+1, 2=2⋅1+02=2\cdot 1+0, so gcd⁡(3,5)=1\gcd(3,5)=1, which divides 88, so solutions exist.

Back-substitute: 1=3−1⋅2=3−1⋅(5−1⋅3)=2⋅3−1⋅51=3-1\cdot 2=3-1\cdot(5-1\cdot 3)=2\cdot 3-1\cdot 5. Multiplying by 88: 2⋅3⋅8−1⋅5⋅8=8⋅12\cdot 3\cdot 8-1\cdot 5\cdot 8=8\cdot 1, i.e. 3⋅16+5⋅(−8)=83\cdot 16+5\cdot(-8)=8, giving one solution (x0,y0)=(16,−8)(x_0,y_0)=(16,-8).

By the general solution theorem with d=1d=1, every solution is x=16+5t, y=−8−3tx=16+5t,\ y=-8-3t for t∈Zt\in\mathbb{Z}. Choosing t=−3t=-3 gives x=16−15=1, y=−8+9=1x=16-15=1,\ y=-8+9=1, matching the coin example.

Among all tt, x=16+5t≥0x=16+5t\ge 0 first fails to hold for t≤−4t\le -4 (giving x=−4x=-4), so the smallest nonnegative xx is at t=−3t=-3: (x,y)=(1,1)(x,y)=(1,1).

Example: RSA key generation: finding a modular inverse

In RSA with public exponent e=7e=7 and φ(n)=40\varphi(n)=40, find the private exponent dd satisfying 7d≡1(mod40)7d\equiv 1\pmod{40}.

Solution

The congruence 7d≡1(mod40)7d\equiv 1\pmod{40} is equivalent to the linear Diophantine equation 7d−40k=17d-40k=1 for some integer kk.

Euclidean algorithm: 40=5⋅7+540=5\cdot 7+5, 7=1⋅5+27=1\cdot 5+2, 5=2⋅2+15=2\cdot 2+1, 2=2⋅1+02=2\cdot 1+0, so gcd⁡(7,40)=1\gcd(7,40)=1, confirming an inverse exists.

Back-substitute: 1=5−2⋅2=5−2⋅(7−1⋅5)=3⋅5−2⋅7=3⋅(40−5⋅7)−2⋅7=3⋅40−17⋅71=5-2\cdot 2=5-2\cdot(7-1\cdot 5)=3\cdot 5-2\cdot 7=3\cdot(40-5\cdot 7)-2\cdot 7=3\cdot 40-17\cdot 7. So 7⋅(−17)+40⋅3=17\cdot(-17)+40\cdot 3=1, giving d≡−17(mod40)d\equiv -17\pmod{40}.

Reducing to the standard range: d≡−17+40=23(mod40)d\equiv -17+40=23\pmod{40}. Checking: 7×23=161=4×40+17\times 23=161=4\times 40+1, confirming d=23d=23 is the correct RSA private exponent for this toy key.

Which condition on d=gcd⁡(a,b)d=\gcd(a,b) decides whether ax+by=cax+by=c has an integer solution?

Bézout's identity guarantees the existence of which integers?

If (x0,y0)(x_0,y_0) solves ax+by=cax+by=c with d=gcd⁡(a,b)d=\gcd(a,b), the general solution is x=x0+bdtx=x_0+\frac{b}{d}t and y=y= ?

The extended Euclidean algorithm used to solve linear Diophantine equations is also the standard method for computing which cryptographic quantity?

References

  1. Wikipedia contributors (2024). Bézout's identity
  2. G. H. Hardy, E. M. Wright (2008). An Introduction to the Theory of Numbers