Divide instead
Division replaces repeated subtraction
Lots of subtracting
Euclid's algorithm takes 99 down to 1 by subtracting 2 again and again: 99 → 97 → 95 → … → 1.
Start with 99 and subtract 2 until you no longer can. What is left?
What this lesson covers
The idea
Repeated subtraction of n from m leaves the remainder m mod n, so division can replace repeated subtraction.
Lots of subtracting
Euclid's algorithm takes 99 down to 1 by subtracting 2 again and again: 99 → 97 → 95 → … → 1.
Start with 99 and subtract 2 until you no longer can. What is left?
- 1, the remainder when 99 is divided by 2
- 0
- 49
Subtract or divide?
Run both versions on gcd(99, 2). Left: Euclid subtracts. Right: reduce using the remainder m mod n in one go. Compare the number of reductions.
One division, many subtractions
Repeatedly subtracting n from m leaves the remainder m mod n, so one division can replace many subtractions.
Indian treatises like Āryabhaṭa's Āryabhaṭīya (499 CE) use division by remainder in place of repeated subtraction. m mod n is the remainder when m is divided by n: 17 mod 5 = 2, 33 mod 7 = 5, 99 mod 2 = 1. For gcd(99, 2): about 50 subtractions, but just 2 divisions.
Notes
Subtracting n from m again and again leaves m mod n, the remainder. One division replaces many subtractions.
Check yourself
What is 33 mod 7?
Answer: 5
33 = 4 × 7 + 5, so 33 mod 7 = 5.
What is 17 mod 5?
Answer: 2
17 = 3 × 5 + 2, so 17 mod 5 = 2.
Subtracting 375 from 825 until we no longer can leaves …
- 75, which is 825 mod 375 — correct. Yes. 825 − 375 − 375 = 75.
- 450. 450 is still more than 375: subtract again.
- 0. 375 does not divide 825 exactly.