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

Greatest common divisor · 3 marks

Suppose we want to compute gcd(375, 825).

Answer: Divisors of 375: [1, 3, 5, 15, 25, 75, 125, 375]; divisors of 825: [1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275, 825]. Common divisors: [1, 3, 5, 15, 25, 75]. So gcd(375, 825) = 75.

Step-by-step solution

Given: Algorithm to find gcd(m, n): 1. Let divisors-of-m be divisors(m). 2. Let divisors-of-n be divisors(n). 3. Start with an empty list common-divisors. 4. For each number x in divisors-of-m, if x also appears in divisors-of-n, add x to common-divisors. 5. Report the rightmost element of common-divisors as gcd(m, n).

Idea: Work straight from the meaning of gcd: list all divisors of each number, keep the ones that appear in both lists, and pick the largest. Because the lists are in increasing order, the largest common divisor is the last one in the common list.

  1. Step 1: divisors-of-m = divisors(375) = [1, 3, 5, 15, 25, 75, 125, 375].½ mark
  2. Step 2: divisors-of-n = divisors(825) = [1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275, 825].½ mark
  3. Steps 3 and 4: start with common-divisors = [ ]. Check each divisor of 375 in the list for 825:
    1 ✓, 3 ✓, 5 ✓, 15 ✓, 25 ✓, 75 ✓, 125 ✗ (825 ÷ 125 = 6.6), 375 ✗ (825 ÷ 375 = 2.2).1 mark
  4. So common-divisors = [1, 3, 5, 15, 25, 75].½ mark
  5. Step 5: the rightmost element is 75. So gcd(375, 825) = 75.½ mark
gcd(375, 825) = 75.

Check: 375 = 5 × 75 and 825 = 11 × 75; 5 and 11 share no factor, so 75 is the greatest ✓.

Answer to write in the exam

divisors(375) = [1, 3, 5, 15, 25, 75, 125, 375]

divisors(825) = [1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275, 825]

1, 3, 5, 15, 25, 75 are in both lists; 125, 375 are not

common-divisors = [1, 3, 5, 15, 25, 75]

∴ gcd(375, 825) = 75 (rightmost element)

Common mistakes that cost marks

  • Missing 11, 33, 55 or 165 in the list for 825, or 125 in the list for 375. These do not change the answer here, but a missed common divisor could.
  • Reporting the rightmost element of divisors-of-m (375) instead of the rightmost common divisor.
  • Adding numbers to the common list that are in only one list (for example 11).

How this can come in the exam

MCQ (1 mark)

Using the lists-of-divisors algorithm, gcd(84, 126) is

  1. 14
  2. 21
  3. 42
  4. 84
Show answer

(C) 42
Common divisors of 84 and 126: [1, 2, 3, 6, 7, 14, 21, 42]. The rightmost is 42.

Try one yourself

Use the lists-of-divisors algorithm to find gcd(45, 75).

Show answer

divisors(45) = [1, 3, 5, 9, 15, 45]; divisors(75) = [1, 3, 5, 15, 25, 75]. Common divisors = [1, 3, 5, 15]. gcd(45, 75) = 15.

More questions like this

All Algorithms questions · All maths questions