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

Assume that m ≥ n. Verify that d divides m and n if and only if d divides both n and m mod n.

Answer: Write m = qn + r, where r = m mod n. If d divides m and n, then d divides r = m − qn. If d divides n and r, then d divides m = qn + r. So the two conditions are equivalent.

Step-by-step solution

Given: m ≥ n ≥ 1; m mod n is the remainder when m is divided by n
To find: Show: d | m and d | n ⇔ d | n and d | (m mod n)

Idea: Division gives m = qn + r with remainder r = m mod n, so r = m − qn. Then argue both ways, just as for gcd(m, n) = gcd(n, m − n): taking away (or adding) whole multiples of n does not change which numbers divide.

  1. Divide m by n: m = qn + r, where q is the quotient and r = m mod n, with 0 ≤ r < n. So r = m − qn.½ mark
  2. If d divides m and n: write m = ad and n = bd. Then r = m − qn = ad − qbd = (a − qb)d, so d divides r = m mod n. And d divides n already.1 mark
  3. If d divides n and m mod n: write n = xd and r = yd. Then m = qn + r = qxd + yd = (qx + y)d, so d divides m. And d divides n already.1 mark
  4. Both directions hold, so d divides m and n if and only if d divides n and m mod n. (If r = 0, every d divides 0 = 0 × d, so the statement still holds.) Example: m = 60, n = 16, r = 12: the common divisors of 60 and 16 are 1, 2, 4, and so are those of 16 and 12.½ mark
With m = qn + r (r = m mod n): d | m, d | n ⇒ d | (m − qn) = r; and d | n, d | r ⇒ d | (qn + r) = m. Hence d divides m and n if and only if d divides n and m mod n. This justifies reducing gcd(m, n) to gcd(n, m mod n).

Check: m = 100, n = 36: 100 mod 36 = 28. Common divisors of 100 and 36: 1, 2, 4. Common divisors of 36 and 28: 1, 2, 4 ✓.

Answer to write in the exam

Let m = qn + r, r = m mod n, 0 ≤ r < n ⇒ r = m − qn

(⇒) d | m, d | n: m = ad, n = bd

r = ad − qbd = (a − qb)d ⇒ d | r

(⇐) d | n, d | r: n = xd, r = yd

m = qxd + yd = (qx + y)d ⇒ d | m

∴ d | m and d | n ⇔ d | n and d | (m mod n)

Common mistakes that cost marks

  • Proving only one direction. “If and only if” needs both: (m, n) ⇒ (n, m mod n) and back.
  • Writing m mod n = m − n. The remainder is m − qn, where q is the quotient (it equals m − n only when q = 1).
  • Verifying with one numerical example and calling it a proof; an example only illustrates the statement.

How this can come in the exam

MCQ (1 mark)

If d divides both 168 and 120, which of these must d also divide?

  1. 48
  2. 20
  3. 36
  4. 7
Show answer

(A) 48
168 mod 120 = 48, and d divides 168 − 1 × 120 = 48.

Try one yourself

Verify the statement for m = 75 and n = 20 by listing common divisors.

Show answer

75 mod 20 = 15. Common divisors of 75 and 20: 1, 5. Common divisors of 20 and 15: 1, 5. The same ✓.

More questions like this

All Algorithms questions · All maths questions