Sub topic 1
Divisibility, factors and multiples
Prerequisites
This chapter assumes you can do the following:
- Multiply and divide integers, and find a quotient and remainder (for example, 47 = 5 × 9 + 2).
- Read exponent notation such as 2³ = 8.
- Rearrange simple equations and work with fractions.
Everything later in this tutorial (divisibility rules, prime factorization, HCF and LCM) uses the vocabulary set here. CAT questions often hide a simple divisibility fact inside a long sentence, so precise definitions save time.
What "divides" means
For integers a and b, with a not equal to 0, we say a divides b when b ÷ a leaves remainder 0. Equivalent statements:
- a is a factor (or divisor) of b.
- b is a multiple of a.
- b = a × k for some integer k.
The notation is a | b. For example, 7 | 63 because 63 = 7 × 9. The statement "7 does not divide 50" is written 7 ∤ 50.
Factors and multiples are two views of the same relationship. Factors of a number are finite and at most the number itself. Multiples are unlimited and at least the number itself.
| Number | Factors | First five multiples |
|---|---|---|
| 12 | 1, 2, 3, 4, 6, 12 | 12, 24, 36, 48, 60 |
| 7 | 1, 7 | 7, 14, 21, 28, 35 |
| 36 | 1, 2, 3, 4, 6, 9, 12, 18, 36 | 36, 72, 108, 144, 180 |
Remember this asymmetry. HCF problems work with the finite side (factors), and LCM problems work with the unlimited side (multiples). Most wrong turns in later chapters come from mixing them up.
The division algorithm
For any integer n and positive integer d, there is exactly one pair q (quotient) and r (remainder) with
n = d × q + r, where 0 ≤ r < d.
Then d | n exactly when r = 0. This identity is the basis of every remainder problem in CAT. Two points matter:
- The remainder is always smaller than the divisor. A remainder of 9 when dividing by 7 is impossible. A CAT question that states it is either wrong or hiding a trick.
- The remainder is never negative in this convention. For n = −7 and d = 3, we get −7 = 3 × (−3) + 2, so the remainder is 2, not −1. Python's
%operator follows the same rule for a positive divisor.
for n, d in [(47, 5), (-7, 3), (36, 9), (4, 9)]:
q, r = divmod(n, d)
print(f"{n} = {d} * {q} + {r}")Output:
47 = 5 * 9 + 2
-7 = 3 * -3 + 2
36 = 9 * 4 + 0
4 = 9 * 0 + 4The last line shows that when the dividend is smaller than the divisor, the quotient is 0 and the remainder is the dividend itself.
Special cases
Several edge cases appear in CAT options and trap questions:
- 1 divides every integer. Every integer divides itself.
- Every nonzero integer divides 0, because 0 = a × 0. So 0 is a multiple of every number. But 0 divides nothing, since division by zero is undefined.
- Negative numbers have the same factors as their absolute value, with signs. CAT questions almost always mean positive factors unless they say "integers".
- 1 has exactly one factor (itself). Every other positive integer has at least two.
Properties you can rely on
These hold for integers a, b, c:
- Reflexive: a | a.
- Transitive: if a | b and b | c, then a | c. Example: 3 | 12 and 12 | 60, so 3 | 60.
- Sums and differences: if a | b and a | c, then a | (b + c) and a | (b − c). More generally, a | (bx + cy) for any integers x and y.
- Products: if a | b, then a | bc for any integer c.
- Comparison: if a | b and b ≠ 0, then |a| ≤ |b|.
- Divisor of a product: if a | bc and a shares no common factor with b (they are coprime), then a | c. This needs the coprime condition. For example, 6 | 4 × 3 = 12, but 6 divides neither 4 nor 3 alone, because 6 and 4 share the factor 2.
Property 3 is the most useful in practice. To test whether a divides a sum, split the sum into pieces you can check. For instance, to find the remainder of 1000 + 7 when dividing by 7, note that 7 | 7 and the remainder of 1000 by 7 is 6, so the remainder is 6.
The converse of property 3 is false. If a divides b + c, it does not follow that a divides b or c. Example: 5 | (2 + 3), but 5 divides neither 2 nor 3.
Finding all factors efficiently
Factors come in pairs. If d divides n, so does n/d, and the two multiply to n. One member of each pair is at most √n. So you only need to test d from 1 up to √n, and each hit gives two factors.
For 36, √36 = 6. Testing 1, 2, 3, 4, 5, 6 gives hits at 1, 2, 3, 4, 6, which produce pairs (1, 36), (2, 18), (3, 12), (4, 9), (6, 6). The pair (6, 6) repeats, so 6 is listed once.
def factors(n):
small, large = [], []
d = 1
while d * d <= n:
if n % d == 0:
small.append(d)
if d != n // d:
large.append(n // d)
d += 1
return small + large[::-1]
print(factors(36)) # [1, 2, 3, 4, 6, 9, 12, 18, 36]
print(factors(97)) # [1, 97]
print(factors(1)) # [1]The check d != n // d prevents listing a square root twice. That is the seed of a result you will see later: a number has an odd count of factors exactly when it is a perfect square.
Worked example 1: using the sum property
Question. Does 9 divide 4 × 10⁶ + 5 × 10³ + 9 × 10 + 6?
Reduce each piece modulo 9 using the division algorithm. Every power of 10 leaves remainder 1 when divided by 9, because 10ⁿ − 1 = 99…9 is a multiple of 9. So the expression leaves the same remainder as 4 + 5 + 9 + 6 = 24, and 24 leaves remainder 6. The answer is no, and the remainder is 6.
This is the same idea behind the digit-sum rule for 9. A later chapter develops it in full. Here the point is that sums can be reduced piece by piece.
Worked example 2: counting multiples in a range
Question. How many multiples of 7 lie between 100 and 500 inclusive?
The number of multiples of k from 1 to N is ⌊N/k⌋. So:
- Multiples of 7 up to 500: ⌊500/7⌋ = 71.
- Multiples of 7 up to 99: ⌊99/7⌋ = 14.
- Answer: 71 − 14 = 57.
Subtracting at 99, not 100, is deliberate, because 100 is included in the range. A common error is to subtract the count at 100, which loses a multiple whenever the lower bound is itself a multiple.
k, lo, hi = 7, 100, 500
print(hi // k - (lo - 1) // k) # 57
print(len([m for m in range(lo, hi + 1) if m % k == 0])) # 57Common errors
- Forgetting 1 and the number itself when counting factors. Every n > 1 has at least 1 and n.
- Listing a square root twice in a factor list, which overcounts by one.
- Off-by-one in range counts. Use ⌊hi/k⌋ − ⌊(lo − 1)/k⌋ for an inclusive range.
- Treating "a | b + c" as "a | b and a | c". Only the forward direction of property 3 is valid.
- Assuming a | bc implies a | b or a | c. It fails unless a is prime (or coprime to one of them), as the 6 | 4 × 3 example shows.
Where this fits
The concept graph for this tutorial starts here. Divisibility rules, primes and prime factorization all build on the definitions above. HCF is the largest number in the finite set of common factors. LCM is the smallest number in the unlimited set of common multiples.
Exercise
How many positive integers between 1 and 1000 inclusive are multiples of 6 but not multiples of 10? (Hint: multiples of both 6 and 10 are the multiples of 30.)
Show answer
Multiples of 6: ⌊1000/6⌋ = 166. Multiples of both 6 and 10, which are multiples of 30: ⌊1000/30⌋ = 33. Answer: 166 − 33 = 133.
Exercise
Write a number n as 15q + r with 0 ≤ r < 15 so that n = 15 × 8 + 11. What is the remainder when 2n is divided by 15?
Show answer
n = 131. Then 2n = 262 = 15 × 17 + 7, so the remainder is 7. A shortcut is to double the remainder (22) and reduce it modulo 15, which also gives 7.
Exercise
True or false: if 12 divides n × 5, then 12 divides n. Explain.
Show answer
True. 12 and 5 are coprime, so by property 6, 12 | 5n implies 12 | n. The result would fail if 5 were replaced by 4, because 12 | 4 × 3 but 12 ∤ 3.