Worked examples — Extended Euclidean algorithm
This page is a drill. The parent note built the machine — the recurrence that walks Bézout coefficients forward. Here we throw every kind of input at that machine and watch it survive: big vs small, coprime vs not, a zero input, negative numbers, a modular-inverse job, a Diophantine word problem, and one exam trap. Miss none of these and no problem can surprise you.
Everything below reuses only two facts from the parent:
- The remainder is what's left after you fit into as many whole times as possible; that count is the quotient .
- We keep two side-columns so that at every row . They start at for and for .
The scenario matrix
We'll cover each cell exactly once. Read the Forecast line and guess before scrolling.
The table shape (and its two starting rows)
Every example is a small table. Each row records five things: the two remainders we're dividing, the quotient , the new remainder , and the two updated coefficients . The engine of the whole table is:
But this recurrence needs two rows to start from — you can't take "two behind" and "one behind" from nothing. Those two starter rows are fixed once and for all:

Let's read the figure with Example 1's first computed row (, from ). The new tile (lavender) is built from (mint, two behind) minus copies of (butter, one behind): . That is exactly the arrow picture — carry the far tile down, then subtract of the near tile. Every example below is just this move, over and over.
Cell A — coprime numbers ()
Cell B — a shared factor ()
Cell C — one number divides the other
Forecast: divides exactly. The algorithm should finish in a single division and the gcd is itself.
Step 1. : remainder immediately. Stop after one step. Why this step? When , the very first division leaves nothing over. The gcd is , sitting in the base row with .
Verify: ✓ The coefficient of collapses to because we never needed at all.
Cell D — a zero input (degenerate)
and Forecast: you can't divide by zero, but you can divide zero by something. What is the gcd of and ? Anything divides , so the biggest divider shared with is itself.
Step 1. For : by definition . No division runs. Bézout: , so . Why this step? The base row already is the answer — the second remainder is , so we stop before any quotient.
Step 2. For : by the same definition , realised by the combination , giving . Why this step? No division happens here either; we just name the combination that produces from the inputs and .
Verify: ✓ and ✓. Both degenerate cases return without a single quotient computed.
is undefined Bézout requires not both zero. With every combination is , so there's no "greatest" divisor.
Cell E — a negative input
and its Bézout pair Forecast: gcd is always taken as positive, so this equals . Only the coefficient signs will differ.
Step 1. Run Extended Euclidean on the absolute values and . Base rows and .
- : . , .
- : . , .
- : . , .
- : . , .
- : stop. Last non-zero remainder with .
So . Why this step? The algorithm's division steps need non-negative remainders, so we work with and derive the pair honestly before dealing with the sign.
Step 2. Put the minus back. We want . Since , take , . Why this step? Replacing just negates the coefficient sitting on ; leave alone.
Verify: ✓ Same gcd, mirrored .
Cell F — modular inverse
Forecast: an inverse exists iff . From Example 1 that gcd is , so it exists. The coefficient that multiplied there was — expect that (mod 101) to be the answer.
Step 1. Example 1 gave . Why this step? Read the equation mod : the term vanishes, leaving . So is the inverse.
Step 2. Push into range . Here is already in range — nothing to add. (If the coefficient had been negative, we'd add until it landed in .) Why this step? Inverses are reported as the smallest non-negative residue.
Verify: , so . ✓
Cell G — Diophantine word problem
Statement. You have unlimited stamps worth 7¢ and 11¢. Can you owe/pay so that the net is exactly 1¢, i.e. solve (negative means "give back")? Find one integer solution. Forecast: and are both prime and different, so , which divides — a solution must exist.
Step 1. The recurrence assumes the leading number is the second, so put . Base rows and . Why this step? Swapping keeps every quotient non-negative so the division steps behave.
Step 2. : . , . Why this step? Carry row down, subtract copy of row — the figure move again.
Step 3. : . , . Why this step? The divisor drops to ; the recurrence now reaches back to rows and .
Step 4. : . , . Why this step? Remainder is now ; the next division will zero out, so this row holds the answer.
Step 5. : stop. So (with ) .
Step 6. Translate back to : the same equation reads , so . Because , no scaling is needed. Why this step? We only swapped the names ; undoing the swap just relabels which coefficient sits on the .
Verify: ✓ (full family: .)
Cell H — no-solution Diophantine
Forecast: . Since any combination of multiples of 3 is a multiple of 3, and is not divisible by 3, there should be no solution.
Step 1. Compute : , then . So . Why this step? The solvability test for is exactly "".
Step 2. Test : , remainder . No solution exists. Stop. Why this step? Failing the divisibility test ends the problem — you never compute coefficients.
Verify: , so no integers can satisfy the equation. ✓ (Sanity: LHS is always a multiple of 3; isn't.)
Cell I — exam twist: which row holds the answer?
Statement. A student runs Extended Euclidean on and and asks: "which row do I read the coefficients from — the last one, where ?" Work the table and settle it. Forecast: the last row has and no valid coefficients. The gcd lives in the second-to-last row.
Step 1. Build the table (base rows and ):
- : . . ()
- : . . ()
- : . . ()
- : . . ()
- : remainder , dashes for coefficients. () Why this step? Running the full table makes the trap visible: the row carries ; the final row carries nothing usable.
Step 2. Report the gcd from the last non-zero remainder: with — from the row, never the row. Why this step? The recurrence runs one step past the gcd to confirm the remainder truly reaches ; that final row is bookkeeping, not the answer.
Verify: ✓ Correct row, correct gcd.
Recall
Recall Which cell forces you to
stop before computing coefficients? Cell H (no solution) ::: If in a Diophantine problem, you halt right after the divisibility test — no Bézout coefficients are needed.
Recall What is
and its Bézout pair? , achieved by ::: the base row is already the answer; no division runs.
Recall What are the two base rows every table starts from?
with and with ::: identity coordinates saying " is one " and " is one ".
Recall Why is the answer in the second-to-last row, never the last?
The last row's remainder is ::: the gcd is the last non-zero remainder, which sits one row up with its coefficients.
Recall How does a negative input
change the Bézout pair? It negates (the coefficient on ) and leaves unchanged ::: because .
Connections
- Extended Euclidean Algorithm — the parent machine every example here drives
- Euclidean Algorithm — the plain gcd loop underneath every row
- Bézout's Identity — guarantees the we keep verifying
- Modular Multiplicative Inverse — Cell F reads straight off the table
- Linear Diophantine Equations — Cells G and H are its solvable / unsolvable faces
- Chinese Remainder Theorem — chains several inverses like Cell F
- RSA Algorithm — private key is one big Cell F computation