Intuition What this page does
The parent note proved the theorem and showed two clean examples. But real problems throw curveballs: negative numbers, one input zero , numbers that are coprime , numbers where one divides the other, and word problems in disguise. This page hunts down every case class so you never meet a scenario you haven't already solved.
Before anything else, recall the single equation everything on this page serves:
Definition The equation we solve every time
Given two whole numbers a and b (not both 0 ), we hunt for two whole numbers x and y — called Bézout coefficients — so that
a x + b y = g cd( a , b ) .
Here g cd( a , b ) is the greatest common divisor : the biggest number that divides both a and b with no remainder. A "whole number" (integer) may be positive, negative, or zero — that freedom to go negative is what makes this possible.
Every Bézout problem falls into one of these cells. The examples below are tagged with the cell they cover.
#
Cell (case class)
What is unusual
Covered by
C1
Both positive, g cd> 1
the "standard" run
Ex 1
C2
Coprime pair, g cd= 1
answer must equal 1
Ex 2
C3
One number divides the other
Euclid stops in one line
Ex 3
C4
A negative input
signs of coefficients flip
Ex 4
C5
One input is zero
degenerate — no algorithm needed
Ex 5
C6
Modular inverse (why we care)
rephrasing a x + m y = 1
Ex 6
C7
Word problem (jugs of water)
translate story → equation
Ex 7
C8
Exam twist: solve a x + b y = c with c = g cd
scale + shift a solution
Ex 8
The tools we lean on: the Euclidean algorithm (repeated division to find the GCD), back-substitution (the extended version that also returns x , y ), and the shift rule for generating all solutions. Each is why -justified as it appears.
x , y with 252 x + 198 y = g cd( 252 , 198 ) .
Forecast: Guess the GCD first. Both are even and both are divisible by 9 (digit sums 9 and 18 )... so g cd is a multiple of 18 . Is it exactly 18 ? Predict, then check.
Step 1 — Run the Euclidean algorithm.
252 &= 198\cdot 1 + 54\\
198 &= 54\cdot 3 + 36\\
54 &= 36\cdot 1 + 18\\
36 &= 18\cdot 2 + 0
\end{aligned}$$
*Why this step?* Each line replaces a big pair by a smaller pair with the **same** GCD (subtracting a multiple of one number changes nothing they both share). The last non-zero remainder, $18$, is $\gcd(252,198)$. Forecast confirmed.
**Step 2 — Back-substitute to reach $18$.** Start from the line that produced $18$:
$$18 = 54 - 36\cdot 1.$$
*Why this step?* We want $18$ written using $252$ and $198$ only. We climb back up, replacing each remainder ($36$, then $54$) by its own earlier expression.
Replace $36 = 198 - 54\cdot 3$:
$$18 = 54 - (198 - 54\cdot 3) = 4\cdot 54 - 198.$$
Replace $54 = 252 - 198\cdot 1$:
$$18 = 4(252 - 198) - 198 = 4\cdot 252 - 5\cdot 198.$$
**Answer:** $x = 4,\; y = -5$.
**Verify:** $252(4) + 198(-5) = 1008 - 990 = 18 = \gcd$. ✓ Notice one coefficient is negative — expected, since two positives must partly cancel.
The figure shows what "smallest positive combination" means: mark every value 252 x + 198 y on the number line and the nearest one above zero lands exactly on 18 .
x , y with 17 x + 5 y = g cd( 17 , 5 ) .
Forecast: 17 is prime and 5 does not divide it, so no factor is shared. Predict g cd= 1 before computing.
Step 1 — Euclidean algorithm.
17 &= 5\cdot 3 + 2\\
5 &= 2\cdot 2 + 1\\
2 &= 1\cdot 2 + 0
\end{aligned}$$
*Why this step?* Same shrinking process; the last non-zero remainder $1$ **is** the GCD, confirming the pair is [[Coprime Integers|coprime]].
**Step 2 — Back-substitute.**
$$1 = 5 - 2\cdot 2.$$
Replace $2 = 17 - 5\cdot 3$:
$$1 = 5 - 2(17 - 5\cdot 3) = 7\cdot 5 - 2\cdot 17.$$
*Why this step?* We express the target $1$ purely in $17$ and $5$.
**Answer:** $x = -2,\; y = 7$.
**Verify:** $17(-2) + 5(7) = -34 + 35 = 1$. ✓ Reaching $1$ is the *signature* of coprimality — this is exactly the setup a modular inverse needs (see Ex 6).
x , y with 30 x + 6 y = g cd( 30 , 6 ) .
Forecast: 6 divides 30 exactly (30 = 6 ⋅ 5 ). When one number divides the other, the smaller one is the GCD. Predict g cd= 6 .
Step 1 — Euclidean algorithm (one line!).
30 = 6 ⋅ 5 + 0.
Why this step? The remainder is 0 immediately, so the divisor 6 is the GCD. No back-substitution chain is needed.
Step 2 — Read off coefficients directly.
Since the GCD is 6 itself, take x = 0 , y = 1 :
30 ( 0 ) + 6 ( 1 ) = 6.
Why this step? We don't need 30 at all — the divisor already equals the GCD, so its coefficient can be 1 and the other 0 .
Answer: x = 0 , y = 1 .
Verify: 30 ( 0 ) + 6 ( 1 ) = 6 = g cd . ✓ (Any ( x , y ) = ( 0 + k , 1 − 5 k ) also works; try k = 1 : 30 ( 1 ) + 6 ( − 4 ) = 30 − 24 = 6 . ✓)
x , y with ( − 24 ) x + 33 y = g cd( − 24 , 33 ) .
Forecast: The GCD ignores signs — it is a magnitude . So g cd( − 24 , 33 ) = g cd( 24 , 33 ) . Both share 3 . Predict g cd= 3 , and expect a sign to flip in the coefficients versus the all-positive version.
Step 1 — Solve the positive version first. Work with 24 and 33 :
33 &= 24\cdot 1 + 9\\
24 &= 9\cdot 2 + 6\\
9 &= 6\cdot 1 + 3\\
6 &= 3\cdot 2 + 0
\end{aligned}$$
So $\gcd(24,33)=3$.
*Why this step?* Signs don't affect divisibility, so it's cleanest to run Euclid on absolute values, then restore signs at the end.
**Step 2 — Back-substitute for $24,33$.**
$$3 = 9 - 6.$$
Replace $6 = 24 - 9\cdot 2$: $\;3 = 9 - (24 - 18) = 3\cdot 9 - 24$.
Replace $9 = 33 - 24$: $\;3 = 3(33 - 24) - 24 = 3\cdot 33 - 4\cdot 24$.
So $24(-4) + 33(3) = 3$.
**Step 3 — Restore the negative sign.** We need $(-24)x$, and we have $24\cdot(-4)$. Since $24\cdot(-4) = (-24)\cdot(4)$, flip the sign of that coefficient:
$$(-24)(4) + 33(3) = 3.$$
*Why this step?* Moving the minus into the variable $a=-24$ means the coefficient must absorb the opposite sign to keep the product identical.
**Answer:** $x = 4,\; y = 3$.
**Verify:** $(-24)(4) + 33(3) = -96 + 99 = 3 = \gcd$. ✓
x , y with 0 ⋅ x + 14 y = g cd( 0 , 14 ) .
Forecast: What divides 0 ? Everything — 0 = 14 ⋅ 0 , so 14 ∣ 0 . Thus the greatest common divisor of 0 and 14 is 14 itself. Predict g cd= 14 . (This is why the theorem forbids both being zero: g cd( 0 , 0 ) has no largest divisor.)
Step 1 — State the GCD. g cd( 0 , 14 ) = 14 .
Why this step? No division loop is possible with a zero; the non-zero number is automatically the GCD.
Step 2 — Pick coefficients. The x term vanishes since a = 0 , so choose x = 1 (it does nothing) and y = 1 :
0 ( 1 ) + 14 ( 1 ) = 14.
Why this step? With a = 0 , only y matters; set y = 1 so b ⋅ y equals the GCD, and x is free.
Answer: x = 1 , y = 1 (indeed x can be any integer).
Verify: 0 ( 1 ) + 14 ( 1 ) = 14 = g cd . ✓ Try x = 7 : 0 ( 7 ) + 14 ( 1 ) = 14 . ✓ Confirms x is genuinely free.
Worked example Find the multiplicative inverse of
7 modulo 26 .
Forecast: An inverse exists iff g cd( 7 , 26 ) = 1 . 7 is prime and doesn't divide 26 , so predict the inverse exists. We are secretly solving 7 x + 26 y = 1 ; the x is the inverse.
Step 1 — Euclidean algorithm.
26 &= 7\cdot 3 + 5\\
7 &= 5\cdot 1 + 2\\
5 &= 2\cdot 2 + 1\\
2 &= 1\cdot 2 + 0
\end{aligned}$$
GCD $= 1$, so the inverse exists.
*Why this step?* [[Modular Arithmetic|Modular]] inverse of $a$ mod $m$ means finding $x$ with $ax \equiv 1 \pmod m$. Bézout gives that $x$ whenever $\gcd(a,m)=1$.
**Step 2 — Back-substitute to $1$.**
$$1 = 5 - 2\cdot 2.$$
Replace $2 = 7 - 5$: $\;1 = 5 - 2(7-5) = 3\cdot 5 - 2\cdot 7$.
Replace $5 = 26 - 7\cdot 3$: $\;1 = 3(26 - 21) - 2\cdot 7 = 3\cdot 26 - 11\cdot 7$.
So $7(-11) + 26(3) = 1$.
**Step 3 — Read the inverse.** The coefficient of $7$ is $x=-11$. Reduce mod $26$: $-11 + 26 = 15$.
*Why this step?* $7x + 26y = 1$ means $7x \equiv 1 \pmod{26}$ (the $26y$ term is $0$ mod $26$). The inverse is $x$ taken in the range $0$ to $25$.
**Answer:** $7^{-1} \equiv 15 \pmod{26}$.
**Verify:** $7\cdot 15 = 105 = 4\cdot 26 + 1$, so $7\cdot 15 \equiv 1 \pmod{26}$. ✓
Worked example You have a
21 -litre jug and a 15 -litre jug and a big tub. By filling and pouring (each full jug adds its size; emptying a jug back subtracts its size), can you measure out exactly 3 litres? How?
Forecast: "Measure c litres with jugs of size a and b " is solvable iff g cd( a , b ) ∣ c . Here g cd( 21 , 15 ) = 3 and 3 ∣ 3 , so predict yes .
Step 1 — Translate to an equation. Let x = net times we use the 21 -jug (pour in = + , empty out = − ), y likewise for the 15 -jug. We want
21 x + 15 y = 3.
Why this step? Every fill adds a jug's volume, every empty subtracts it, so the net measured amount is a linear combination — exactly Bézout.
Step 2 — Euclidean algorithm.
21 &= 15\cdot 1 + 6\\
15 &= 6\cdot 2 + 3\\
6 &= 3\cdot 2 + 0
\end{aligned}$$
$\gcd = 3$ divides $3$. ✓
**Step 3 — Back-substitute.**
$$3 = 15 - 6\cdot 2.$$
Replace $6 = 21 - 15$: $\;3 = 15 - 2(21 - 15) = 3\cdot 15 - 2\cdot 21$.
So $21(-2) + 15(3) = 3$.
*Why this step?* This tells the physical recipe: use the $21$-jug $2$ times as an **empty** ($-2$) and the $15$-jug $3$ times as a **fill** ($+3$).
**Answer:** Fill the $15$-jug **three** times (pour $45$ L into the tub) and empty the $21$-jug **twice** (remove $42$ L), leaving $3$ L. $x=-2,\;y=3$.
**Verify:** $21(-2) + 15(3) = -42 + 45 = 3$ litres. ✓ Units: litres in, litres out, litres remaining — consistent.
252 x + 198 y = 90 for integers, and give all solutions.
Forecast: From Example 1, g cd( 252 , 198 ) = 18 . Is 90 a multiple of 18 ? 90 = 18 ⋅ 5 , yes — so predict solutions exist. This connects to linear Diophantine equations .
Step 1 — Check solvability. a x + b y = c has integer solutions iff g cd∣ c . Here 18 ∣ 90 . ✓
Why this step? Any combination of 252 and 198 is a multiple of their GCD 18 ; a target not divisible by 18 is unreachable.
Step 2 — Scale the base Bézout solution. From Ex 1, 252 ( 4 ) + 198 ( − 5 ) = 18 . Multiply the whole equation by g cdc = 18 90 = 5 :
252 ( 4 ⋅ 5 ) + 198 ( − 5 ⋅ 5 ) = 18 ⋅ 5 = 90.
So a particular solution is x 0 = 20 , y 0 = − 25 .
Why this step? Scaling both sides by the same factor keeps the equality and lands us on the desired right-hand side 90 .
Step 3 — Generate all solutions with the shift rule. With d = g cd= 18 :
x = x 0 + k ⋅ d b = 20 + k ⋅ 18 198 = 20 + 11 k ,
y = y 0 − k ⋅ d a = − 25 − k ⋅ 18 252 = − 25 − 14 k , k ∈ Z .
Why this step? Adding d b to x and subtracting d a from y changes the total by a d b − b d a = 0 , so every k gives another valid pair.
Answer: x = 20 + 11 k , y = − 25 − 14 k .
Verify: Base k = 0 : 252 ( 20 ) + 198 ( − 25 ) = 5040 − 4950 = 90 . ✓ Now k = 1 : x = 31 , y = − 39 , 252 ( 31 ) + 198 ( − 39 ) = 7812 − 7722 = 90 . ✓
The figure plots the solution pairs ( x , y ) for several k : they land on a straight line of step ( + 11 , − 14 ) — the lattice of all Diophantine solutions .
Recall Which cell am I in? (quick decision table)
Is one input 0 ? ::: Cell C5 — the non-zero number is the GCD; the other coefficient is free.
Does one number divide the other exactly? ::: Cell C3 — Euclid ends in one line; use x = 0 , y = 1 style.
Is g cd( a , b ) = 1 ? ::: Cell C2/C6 — you can reach 1 ; the coefficient of a is a 's modular inverse.
Is there a negative input? ::: Cell C4 — solve with absolute values, then push the sign into the variable.
Right-hand side isn't the GCD? ::: Cell C8 — check g cd∣ c , scale by c / g cd , then shift by ( b / d , − a / d ) .
Mnemonic The whole page in one breath
"Run Euclid down, climb back up, scale to the target, then slide by the step."
Down = find GCD; up = get one ( x , y ) ; scale = hit any valid c ; slide = list all solutions.