2.5.8 · D3Number Theory (Intermediate)

Worked examples — Extended Euclidean algorithm

2,793 words13 min readBack to topic

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:

Figure — Extended Euclidean algorithm

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


Cell D — a zero input (degenerate)


Cell E — a negative input


Cell F — modular inverse


Cell G — Diophantine word problem


Cell H — no-solution Diophantine


Cell I — exam twist: which row holds the answer?


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