๐Ÿ  Home โ€บ ๐Ÿ” Number Theory โ€บ Lesson 5

โšก Euclid's Algorithm โ€” Proven, and Run in Reverse

๐Ÿ“– Lesson 5 of 8

๐Ÿ“Œ Key idea of this section

GCF(big, small) = GCF(small, remainder). Repeat until the remainder is 0.
Then run the steps BACKWARDS to write the GCF as a combination of the two numbers.

The fingerprint method has one weakness: you have to factor both numbers first. What if the numbers are big and stubborn? Enter one of the oldest algorithms on Earth โ€” and this time, we prove it before we use it.

Why it works (the proof)

Setup: divide a by b and write the result in the standard form

a = b ร— q + r        (q is the quotient, r is the remainder, 0 โ‰ค r < b)

Example to keep in view: 84 = 48 ร— 1 + 36. Now the claim: GCF(a, b) = GCF(b, r). The proof uses the combination lemma from Lesson 4, in both directions:

And that's the whole algorithm: swap (big, small) for (small, remainder), repeat until the remainder hits 0, and the last nonzero remainder is the GCF.

The algorithm, flowing

84 = 48 ร— 1 + 36
48 = 36 ร— 1 + 12
36 = 12 ร— 3 + 0    โ†’    GCF(84, 48) = 12 โœ…

Three divisions, zero factoring. Fingerprint check: 84 = 2ยฒ ร— 3 ร— 7 and 48 = 2โด ร— 3 โ†’ shared 2ยฒ ร— 3 = 12. Euclid agrees. โœ…

One more, bigger: GCF(252, 198).

252 = 198 ร— 1 + 54
198 = 54 ร— 3 + 36
 54 = 36 ร— 1 + 18
 36 = 18 ร— 2 + 0    โ†’    GCF = 18 โœ…

Fingerprint check: 252 = 2ยฒ ร— 3ยฒ ร— 7 and 198 = 2 ร— 3ยฒ ร— 11 โ†’ shared 2 ร— 3ยฒ = 18. Two methods, one answer โ€” always reassuring.

The reverse gear: Bรฉzout's identity

Now for the honors superpower. Read the Euclid lines for (84, 48) BACKWARDS to express the GCF as a combination of 84 and 48:

12 = 48 โˆ’ 36 ร— 1             from the middle line, solved for 12
   = 48 โˆ’ (84 โˆ’ 48 ร— 1)      substitute 36 = 84 โˆ’ 48 ร— 1 (top line)
   = 48 โˆ’ 84 + 48            distribute the minus sign
   = 2 ร— 48 โˆ’ 1 ร— 84         collect like terms
Check: 2 ร— 48 โˆ’ 84 = 96 โˆ’ 84 = 12 โœ…

So 12 = 2ร—48 + (โˆ’1)ร—84 โ€” the GCF is written as an integer COMBINATION of the two original numbers (negative coefficients allowed!). This fact is called Bรฉzout's identity: GCF(a, b) can always be written as mร—a + nร—b for some integers m and n. It looks like a party trick, but it's the beating heart of internet security: the codes that protect messages start by finding exactly these combinations, with Euclid's algorithm, on gigantic numbers.

A word from history

This procedure appeared in Euclid's book Elements around 300 BC โ€” over 2,300 years ago โ€” making it possibly the oldest algorithm still in daily use. Secure connections on the internet run versions of it every single day. Not bad for a geometry teacher from ancient Alexandria.

โœ๏ธ Your Turn!

  • 1.
    Use Euclid's algorithm to find GCF(90, 126). Show every line.
  • 2.
    Now reverse it: write your answer as a combination m ร— 90 + n ร— 126.
๐Ÿ‘€ Show the answers

Answers:

  • 1.
    126 = 90 ร— 1 + 36; 90 = 36 ร— 2 + 18; 36 = 18 ร— 2 + 0 โ†’ GCF = 18.
  • 2.
    From the middle line: 18 = 90 โˆ’ 36 ร— 2. From the top line: 36 = 126 โˆ’ 90 ร— 1.
    Substitute: 18 = 90 โˆ’ (126 โˆ’ 90) ร— 2 = 90 โˆ’ 2ร—126 + 2ร—90 = 3ร—90 โˆ’ 2ร—126.
    Check: 3ร—90 โˆ’ 2ร—126 = 270 โˆ’ 252 = 18 โœ…
    (Fingerprint confirmation: 90 = 2 ร— 3ยฒ ร— 5 and 126 = 2 ร— 3ยฒ ร— 7 โ†’ shared 2 ร— 3ยฒ = 18.)
V.3.1