Euclid's algorithm: replace the pair by the remainder until it stops
A plain-language explanation of the euclidean algorithm. The idea in plain words, a worked example, and a check with the answers shown — part of the free Quantitative Reasoning guides.
Euclid's algorithm finds a gcd by repeated division, without factoring either number:
repeated until the remainder is 0. The last non-zero remainder is the gcd.
A worked run on:
| step | pair | division | |---|---|---| | 1 | (48, 18) | | | 2 | (18, 12) | | | 3 | (12, 6) | |
The last non-zero remainder is 6, so.
Why it works: any common divisor of and divides, so the set of common divisors does not change when the pair is replaced. The numbers shrink, so the process ends — and when it does, the gcd is the last non-zero value.
This is much faster than factoring for large numbers, which is why it is the algorithm a computer uses.
The key fact is that where.
To see it, write. Any dividing both and divides, hence divides. And any dividing both and divides. So the two pairs have exactly the same common divisors — and therefore the same greatest one.
That invariance is the whole algorithm: each step preserves the answer while making the numbers smaller, so the answer is unchanged at the end, when one number is 0 and the other is visibly the gcd.
Termination: the remainder is strictly less than the divisor and non-negative, so the pair's second component decreases at every step and must reach 0.
Find.
Step one.. (Check:, and.)
Step two.. , remainder 21.)
Step three.. .)
Answer. The last non-zero remainder is 21, so.
The check. and: both exact. And 22 = 2 · 11 and 51 = 3 · 17 share no prime, so 21 is the greatest — the check is the coprimality of the two quotients, which is exactly what "greatest" requires.
- Run Euclid's algorithm to find a gcd
- Explain why replacing the pair does not change the common divisors
- Say why the algorithm terminates
- 1. Run Euclid on.
- 2. Run Euclid on.
- 3. Why can the algorithm not run forever?
Answers
1.;. Answer 6. 2.;;. Answer 5. 3. Each remainder is smaller than the divisor before it, so the second component strictly decreases; a decreasing sequence of non-negative integers must reach 0.