Sub topic 5
Divisibility tests seen as remainders
This chapter assumes you can write a number as divisor × quotient + remainder, read congruence notation such as a ≡ b (mod n), and reduce sums and products of remainders. It also assumes you know that 10 can be replaced by its remainder in a product. Those ideas come from the earlier chapters.
A test is a remainder shortcut
A divisibility test answers "is the remainder 0?". Every classic test does more than that. It computes the remainder itself, from a few digits or from a digit sum, without dividing the whole number.
The tests work because of one fact about place values. Write a number N with digits dk … d1 d_0:
N = d0 + d1·10 + d2·10² + … + dk·10^k
If you know the remainder of each power of 10 for a modulus n, you can swap each power for that remainder. The congruence rules for sums and products allow this. The tests then fall into three groups.
| Modulus | Remainder of powers of 10 | What you compute | Result |
|---|---|---|---|
| 2, 5, 10 | 10 ≡ 0 | Last digit | Remainder of the last digit mod 2, 5 or 10 |
| 4, 25 | 100 ≡ 0 | Last two digits | Remainder of that two-digit number |
| 8, 125 | 1000 ≡ 0 | Last three digits | Remainder of that three-digit number |
| 3, 9 | 10 ≡ 1, so 10^i ≡ 1 | Sum of all digits | Remainder of the digit sum |
| 11 | 10 ≡ −1, so 10^i ≡ (−1)^i | Alternating sum of digits | Remainder of the alternating sum |
Group 1: moduli that divide a power of 10
If n divides 10^k, then 10^k, 10^(k+1) and every higher power leave remainder 0. Only the last k digits can affect the remainder, so you can discard everything else.
- Mod 2 and mod 5 use k = 1. 10 = 2 × 5, so only the last digit matters.
- Mod 4 and mod 25 use k = 2. 100 = 4 × 25, so only the last two digits matter.
- Mod 8 and mod 125 use k = 3. 1000 = 8 × 125, so only the last three digits matter.
Take N = 74381. For the remainder on division by 4, use the last two digits: 81 = 4 × 20 + 1, so the remainder is 1. For the remainder on division by 8, use the last three digits: 381 = 8 × 47 + 5, so the remainder is 5. You can check the second one by writing 74381 = 74000 + 381. Since 74000 = 74 × 1000 and 8 divides 1000, only 381 matters.
Group 2: the digit sum, for 3 and 9
Here 10 ≡ 1 (mod 9). Raising both sides to any power gives 10^i ≡ 1. Substituting into the place-value expansion gives:
N ≡ d0 + d1 + d_2 + … (mod 9)
So N leaves the same remainder mod 9 as its digit sum does. The same argument works mod 3, because 10 ≡ 1 (mod 3) as well. This is the "casting out nines" check.
For 74381 the digit sum is 7 + 4 + 3 + 8 + 1 = 23. Then 23 = 9 × 2 + 5, so the remainder mod 9 is 5. Mod 3, the remainder of 23 is 2.
You can repeat the digit sum until one digit is left. That shortens a long number, but remember the last step: a final digit sum of 9 means remainder 0, not 9.
Finding a missing digit
Problem: for which digit d is the number 5d372 divisible by 9?
The digit sum is 5 + d + 3 + 7 + 2 = 17 + d. It must be a multiple of 9, and 17 + d lies between 17 and 26, so 17 + d = 18 and d = 1. Check: 51372 = 9 × 5708.
Group 3: the alternating sum, for 11
Here 10 ≡ −1 (mod 11), so 10^i ≡ (−1)^i. Even powers give +1 and odd powers give −1. Starting from the units digit:
N ≡ d0 − d1 + d2 − d3 + … (mod 11)
The alternating sum can be negative. Add 11 until the result is between 0 and 10.
Take N = 5678901. Reading digits from the right gives 1, 0, 9, 8, 7, 6, 5. The alternating sum is 1 − 0 + 9 − 8 + 7 − 6 + 5 = 8, so the remainder mod 11 is 8.
For 74381 the digits from the right are 1, 8, 3, 4, 7. The sum is 1 − 8 + 3 − 4 + 7 = −1. Since −1 ≡ 10 (mod 11), the remainder is 10.
Checking the rules in code
This script implements each shortcut and compares it with Python's % operator on every number from 1 to 99,999.
def digits_right_to_left(n):
return [int(ch) for ch in reversed(str(n))]
def rem9(n):
return sum(digits_right_to_left(n)) % 9
def rem11(n):
ds = digits_right_to_left(n)
return sum(d * (-1) ** i for i, d in enumerate(ds)) % 11
def rem4(n):
return (n % 100) % 4
def rem8(n):
return (n % 1000) % 8
n = 74381
print(rem9(n), rem11(n), rem4(n), rem8(n)) # 5 10 1 5
print(n % 9, n % 11, n % 4, n % 8) # 5 10 1 5
for m in range(1, 100000):
assert rem9(m) == m % 9
assert rem11(m) == m % 11
assert rem4(m) == m % 4
assert rem8(m) == m % 8
print("all checks passed")Combining tests for composite divisors
To test divisibility by a composite number, factor it into pairwise coprime parts and test each part. Two numbers are coprime when their only common factor is 1.
- 6 = 2 × 3. Test the last digit for 2 and the digit sum for 3.
- 12 = 3 × 4. Test the digit sum and the last two digits.
- 36 = 4 × 9. Test the last two digits and the digit sum.
- 72 = 8 × 9. Test the last three digits and the digit sum.
- 99 = 9 × 11. Test the digit sum and the alternating sum.
The same idea gives remainders when the divisor is small. Take 7359 and divide by 12. Mod 3 the digit sum is 24, which is 0. Mod 4 the last two digits give 59, which leaves 3. You need a number from 0 to 11 that is 0 mod 3 and 3 mod 4. The candidate 3 works, so the remainder is 3. Check: 7359 = 12 × 613 + 3.
This works for small moduli because you can list candidates. The general method is the Chinese Remainder Theorem, which a later chapter covers.
A test for 7, 11 and 13 together
Since 1001 = 7 × 11 × 13 and 1000 ≡ −1 (mod 1001), split the number into groups of three digits from the right. Add and subtract the groups alternately, starting with plus on the rightmost group. The result has the same remainder as N modulo 7, modulo 11 and modulo 13.
Take N = 123456. The groups are 123 and 456, and 456 − 123 = 333.
- 333 = 7 × 47 + 4, so N leaves remainder 4 mod 7.
- 333 = 11 × 30 + 3, so N leaves remainder 3 mod 11.
- 333 = 13 × 25 + 8, so N leaves remainder 8 mod 13.
You can confirm each against 123456 = 7 × 17636 + 4, and similarly for 11 and 13. This is slower than the 9 and 11 rules, so use it only when the problem involves 7 or 13 and the number is long.
Choosing a test
Common errors
- Reporting a digit sum of 9, 18 or 27 as the remainder mod 9. The remainder is 0.
- Applying the mod 9 test to find a remainder mod 18 or mod 27. The digit sum only tells you about 3 and 9.
- Using the last two digits for mod 8. Mod 8 needs three digits, because 100 = 8 × 12 + 4 is not a multiple of 8.
- Forgetting to normalise a negative alternating sum before reporting it.
- Splitting a composite divisor into factors that share a prime, as in the 2 and 6 example.
Exercise
A six-digit number 4x7y52... is not the plan here. Use this one: the number 3a46b has digits a and b, and it must be divisible by 4 and by 9 at the same time. Find all possible pairs (a, b), where a and b are single digits.
Show answer
Divisibility by 4 depends on the last two digits, 6b. Candidates are 60, 64 and 68, so b is 0, 4 or 8 (62, 66 are not multiples of 4). Divisibility by 9 needs the digit sum 3 + a + 4 + 6 + b = 13 + a + b to be a multiple of 9. With a between 0 and 9, a + b lies between 0 and 17, so 13 + a + b is 18 or 27. That means a + b = 5 or 14. For b = 0 we need a = 5 (or 14, impossible). For b = 4 we need a = 1 or 10, so a = 1. For b = 8 we need a = −3 (impossible) or 6, so a = 6. The pairs are (5, 0), (1, 4) and (6, 8). Check one: 35460 = 4 × 8865 and its digit sum is 18.
Exercise
Find the remainder when 9,080,807 is divided by 11, and the remainder when it is divided by 9.
Show answer
Mod 11: read the digits from the right as 7, 0, 8, 0, 8, 0, 9. The alternating sum is 7 − 0 + 8 − 0 + 8 − 0 + 9 = 32, and 32 = 11 × 2 + 10, so the remainder is 10. Mod 9: the digit sum is 9 + 0 + 8 + 0 + 8 + 0 + 7 = 32, and 32 = 9 × 3 + 5, so the remainder is 5.