Divisors occur in pairs. For instance, the divisors of 18 are (1, 18), (2, 9) and (3, 6).
- (i) If we write out divisors in pairs, how many numbers do we have to examine between 1 and n to find all the divisors of n?
- (ii) If we list out the divisors in pairs, will our gcd algorithm still work in the manner we have described?
Step-by-step solution
Idea: If j divides n, so does n ÷ j, and one of the two is at most √n. So finding the small partner of each pair finds the big one too. But the gcd algorithm relied on the lists being in increasing order.
(i) If we write out divisors in pairs, how many numbers do we have to examine between 1 and n to find all the divisors of n?
- If j divides n, then n = j × (n ÷ j), so n ÷ j is also a divisor: its partner.
- In each pair, the smaller number is at most √n: if both were bigger than √n, their product would be bigger than √n × √n = n.1 mark
- So we only need to examine j = 1, 2, 3, … while j × j ≤ n, that is, up to √n. Each j that divides n gives the pair (j, n ÷ j). That is about √n numbers instead of n.½ mark
- Example: n = 18, √18 ≈ 4.2. Examine 1, 2, 3, 4: 1 → (1, 18), 2 → (2, 9), 3 → (3, 6), 4 does not divide. Only 4 checks instead of 18. (If n is a perfect square, e.g. 36, the pair (6, 6) gives just one divisor.)½ mark
(ii) If we list out the divisors in pairs, will our gcd algorithm still work in the manner we have described?
- Our gcd algorithm reports the rightmost element of the list of common divisors. That is the greatest only because the divisor lists were in increasing order.½ mark
- Listed in pairs, the divisors are not in increasing order: 18 gives 1, 18, 2, 9, 3, 6. For 375 the pair list is [1, 375, 3, 125, 5, 75, 15, 25].½ mark
- Run the algorithm for gcd(375, 825) with this list: keep each number that also divides 825. Common divisors come out as [1, 3, 5, 75, 15, 25]. The rightmost is 25, but gcd(375, 825) = 75. So the algorithm does not work as described.½ mark
- Fix: report the largest element of common-divisors instead of the rightmost, or rearrange the divisors in increasing order first (write the small members of the pairs in order, then the large members in reverse: 1, 2, 3, 6, 9, 18).½ mark
Check: Pairs of 18 found from j = 1 to 4: 1 × 18 = 2 × 9 = 3 × 6 = 18 ✓. 375 ÷ 75 = 5 and 825 ÷ 75 = 11, so 75 (not 25) is the gcd ✓.
Answer to write in the exam
(i)
If j divides n, so does n ÷ j (pair: j × (n ÷ j) = n).
Smaller member of each pair ≤ √n (else product > n).
So examine only j = 1, 2, …, with j × j ≤ n (about √n numbers).
e.g. n = 18: examine 1, 2, 3, 4 → (1, 18), (2, 9), (3, 6)
∴ Only the numbers from 1 to √n need to be examined.
(ii)
gcd algorithm reports the rightmost common divisor; correct only if the lists are increasing.
Pair listing: 1, 18, 2, 9, 3, 6, … is not increasing.
e.g. 375 → [1, 375, 3, 125, 5, 75, 15, 25]; common with divisors of 825 → [1, 3, 5, 75, 15, 25]
Rightmost = 25, but gcd(375, 825) = 75 ✗
∴ No, not as described; report the largest common divisor, or sort the list first.
Common mistakes that cost marks
- Answering “n ÷ 2 numbers” (half of n). Checking up to √n is enough, which is far fewer for large n.
- In (ii), saying the algorithm fails because some divisors are missed. All divisors are still found; the problem is only their order.
- Counting the middle divisor of a perfect square twice (6 in 36 = 6 × 6).
How this can come in the exam
To find all the divisors of 400 by pairs, the largest number that must be examined is
- 20
- 40
- 200
- 400
Show answer
(A) 20
√400 = 20. Every divisor above 20 is the partner of one below 20.
Try one yourself
List the divisors of 72 in pairs. How many numbers did you examine?
Show answer
√72 ≈ 8.5, so examine 1 to 8: (1, 72), (2, 36), (3, 24), (4, 18), (6, 12), (8, 9). 8 numbers examined, 12 divisors found.
More questions like this
- Let us keep track of a quantity called most-recent-common-divisor. We know that 1 is always a common divisor, so we can start with most-recent-common-divisor set to 1. We then scan all numbers from 2 to min(m, n). For each k from 2 to min(m, n), if k divides both m and n, update most-recent-common-divisor to k. Example: Let m = 6, n = 12.
- How would our original algorithm change if we computed the divisors of n by examining the numbers from 1 to n in reverse order, from n down to 1?
- What about the last algorithm described above? What happens when we look at common divisors starting from min(m, n) and work backwards to 1?
- Let us assume that m ≥ n. Then, gcd(m, n) is the same as gcd(n, m − n). Why is this the case?
- 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.