Euclid's algorithm
Euclid's subtraction algorithm
Same problem, new way
Put the pieces together: the reduction gcd(m, n) = gcd(n, m − n), and the stop at gcd(m, 0). The book applies it to the problem we saw before, gcd(375, 825).
375 < 825. What should happen first?
What this lesson covers
The idea
Swap so m ≥ n; if n = 0 report m; otherwise reduce to gcd(n, m – n) and repeat.
Same problem, new way
Put the pieces together: the reduction gcd(m, n) = gcd(n, m − n), and the stop at gcd(m, 0). The book applies it to the problem we saw before, gcd(375, 825).
375 < 825. What should happen first?
- Reverse the numbers: gcd(825, 375)
- Subtract: 375 − 825
- Stop: the answer is 375
Run Euclid's algorithm
Euclid's algorithm for gcd(m, n) 1. If m < n, reverse the numbers and compute gcd(n, m). 2. If n = 0, report the answer as m. 3. Otherwise, reduce the problem to computing gcd(n, m − n). Press Next step and follow every step for gcd(375, 825).
Swap, stop or subtract
Euclid's algorithm: if m < n, swap; if n = 0, report m; otherwise reduce gcd(m, n) to gcd(n, m − n) and repeat.
gcd(375, 825) → gcd(825, 375) → gcd(375, 450) → gcd(450, 375) → gcd(375, 75) → gcd(75, 300) → gcd(300, 75) → gcd(75, 225) → gcd(225, 75) → gcd(75, 150) → gcd(150, 75) → gcd(75, 75) → gcd(75, 0). The problem was reduced 7 times before the answer: 75.
Notes
Euclid: 1. if m < n, swap. 2. if n = 0, report m. 3. otherwise reduce to gcd(n, m − n). Repeat.
Check yourself
We reach gcd(375, 450). What is the next step?
Running the algorithm for gcd(375, 825), how many times is Step 3 (the reduction) used?
Answer: 7
The book counts 7 reductions before the answer.
Use Euclid's algorithm: gcd(60, 16) = ?
Answer: 4
gcd(60, 16) → gcd(16, 44) → … → gcd(4, 0), so the answer is 4.
- 375 < 450, so reverse: gcd(450, 375) — correct. Yes, Step 1.
- Reduce to gcd(450, 75). First the numbers must be in order, m ≥ n.
- Report 375. We only report when n = 0.