Learnify Academy is a tuition centre in Bahrain. Classes are for students in Bahrain only.Tuition classes in Bahrain only

Euclid’s algorithm · 3 marks

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 compute gcd(n, m − n). Let us apply this algorithm to gcd(375, 825), the problem that we saw before.

Answer: gcd(375, 825) → gcd(825, 375) → gcd(375, 450) → gcd(450, 375) → gcd(375, 75) → gcd(75, 300) → … → gcd(75, 75) → gcd(75, 0), so gcd(375, 825) = 75, after 7 subtraction steps.

Step-by-step solution

Idea: Each subtraction replaces the pair by a smaller pair with the same gcd, because gcd(m, n) = gcd(n, m − n). Keep the larger number first, and stop when the second number becomes 0.

  1. 375 < 825, so Step 1: reverse → gcd(825, 375).
    Step 3: 825 − 375 = 450 → gcd(375, 450).½ mark
  2. 375 < 450, so reverse → gcd(450, 375).
    Step 3: 450 − 375 = 75 → gcd(375, 75).½ mark
  3. Step 3: 375 − 75 = 300 → gcd(75, 300). Reverse → gcd(300, 75).
    Step 3: 300 − 75 = 225 → gcd(75, 225). Reverse → gcd(225, 75).½ mark
  4. Step 3: 225 − 75 = 150 → gcd(75, 150). Reverse → gcd(150, 75).
    Step 3: 150 − 75 = 75 → gcd(75, 75).½ mark
  5. Step 3: 75 − 75 = 0 → gcd(75, 0).½ mark
  6. Now n = 0, so Step 2 gives the answer 75. Step 3 (the reduction) was used 7 times.½ mark
gcd(375, 825) = 75 (7 reductions).

Check: The list method gives the same: common divisors of 375 and 825 are 1, 3, 5, 15, 25, 75, so the gcd is 75 ✓.

Answer to write in the exam

gcd(375, 825) = gcd(825, 375) (375 < 825, reverse)

= gcd(375, 450) = gcd(450, 375) (825 − 375 = 450)

= gcd(375, 75) (450 − 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)

∴ gcd(375, 825) = 75

Common mistakes that cost marks

  • Subtracting the larger number from the smaller (375 − 825) instead of reversing first.
  • Stopping at gcd(75, 75) without the last step; the rule says stop only when the second number is 0 (the answer is the same, 75, but the steps are incomplete).
  • Writing gcd(n, m − n) with the numbers in the wrong places, e.g. gcd(450, 825).

How this can come in the exam

MCQ (1 mark)

Using Euclid’s subtraction algorithm, gcd(91, 35) is

  1. 1
  2. 7
  3. 13
  4. 35
Show answer

(B) 7
gcd(91, 35) → gcd(35, 56) → gcd(56, 35) → gcd(35, 21) → gcd(21, 14) → gcd(14, 7) → gcd(7, 7) → gcd(7, 0) = 7.

Try one yourself

Use Euclid’s subtraction algorithm to find gcd(48, 18).

Show answer

gcd(48, 18) → gcd(18, 30) → gcd(30, 18) → gcd(18, 12) → gcd(12, 6) → gcd(6, 6) → gcd(6, 0). gcd(48, 18) = 6.

More questions like this

All Algorithms questions · All maths questions