Divisibility Tests

Divisibility Tests
Everyone already knows certain divisibility tests. For instance, a number
(written in base-10 notation) is divisible by 10 iff its last digit is a 0, divisible
by 100 iff its last two digits are 00, etc. A number is divisible by 5 iff its last
digit is 0 or 5, and divisible by 25 iff its last two digits are 00, 25, 50, or 75.
And we all know that a number is even iff its last digit is 0,2,4,6,or 8.
Did you know that a number is divisible by 9 iff the sum of its digits is
divisible by 9? And that the same works if we replace 9 by 3? How are such
facts proved? How can we generalize them?
Questions like these are the subject of this lecture. This is not exactly
deep mathematics, but it can be entertaining. As we will see, the theory of
congruences is very useful for studying such questions.
From now on we assume that a given positive integer n is written in base-10
notation, as n = (ak ak−1 · · · a2 a1 a0 )10 . Let me remind you that this is just
shorthand for
k
X
n=
ai 10i .
(1)
i=0
Theorem. For any j ≤ k, n is divisible by 2j iff (aj−1 · · · a1 a0 )10 is divisible
by 2j .
This says that we only have to check the last j decimal digits of n to see if
n is divisible by 2j . For instance, 209816 is divisible by 2, 4, and 8, but not
by 16 or any higher power of 2.
Proof. Because 10 ≡ 0 (mod 2), it follows that 10j ≡ 0 (mod 2j ), for each
j. Hence (1) implies
j−1
X
n≡
ai 10i (mod 2j )
i=0
and in the base-10 notation this says that
n ≡ (aj−1 · · · a1 a0 )10
(mod 2j ).
This congruence implies the theorem, because if either side of the congruence
is congruent to 0 then the other side must be congruent to 0 also.
1
Theorem. For any j ≤ k, n is divisible by 5j iff (aj−1 · · · a1 a0 )10 is divisible
by 5j .
The proof is quite similar to the proof of the previous result, and left as an
exercise.
The result says that in order to check n for divisibility by 5j we only need to
check the number formed by the last j digits of n. For instance, 71093375
is divisible by 5, 25, and 125, but not by 625 or any higher power of 5.
Theorem. The positive integer n is divisible by 3 or 9 iff the sum of its
decimal digits is divisible by 3 or 9.
Proof. Observe that for any i we have 10i ≡ 1 (mod 9) and thus also 10i ≡ 1
(mod 3). Thus
n=
k
X
i=0
ai 10i ≡
k
X
ai
(mod 9 or 3)
i=0
and the claim is proved.
For instance, 602185104300 is divisible by 3 but not by 9, because the sum
of the digits is 30, which is divisible by 3 but not 9.
Similarly, 602105104008 is divisible by both 3 and 9, since the sum of the
digits is 27, which is divisible by both 3 and 9.
Theorem. A number n = (ak · · · a2 a1 a0 )10 is divisible by 11 iff a0 − a1 +
a2 − a3 + · · · + (−1)k ak is divisible by 11.
The proof, which is based on the fact that 10 ≡ −1 (mod 11), is an exercise.
For example, the number 395307 is divisible by 11 because 7 − 0 + 3 − 5 +
9 − 3 = 11 is divisible by 11. On the other hand, 161053 is not divisible by
11 because 3 − 5 + 0 − 1 + 6 − 1 = 2 is not divisible by 11.
The next result simultaneously tests for divisibility by 7, 11, and 13.
Theorem. A number n = (ak ak−1 · · · a2 a1 a0 )10 is divisible 7, 11, or 13 iff
(a2 a1 a0 )10 − (a5 a4 a3 )10 + (a8 a7 a6 )10 + · · · is divisible by 7, 11, or 13.
2
For example, 12782410823 is divisible by 7 and 13 but not by 11, since
823 − 410 + 782 − 12 = 1183 is divisible by 7 and 13 but not 11. (To see
that 1183 is divisible by 7 and 13 but not 11, apply the same test again to
1183! Since 183 − 1 = 182 = 2 · 7 · 13 is divisible by 7 and 13 but not 11, it
follows that the same is true of 1183.)
Proof of the theorem. The proof is based on the observation that 7 · 11 · 13 =
1001, and 1000 ≡ −1 (mod 1001). Hence
(ak ak−1 · · · a2 a1 a0 )10 = a0 + a1 10 + a2 102 + · · ·
= (a0 + 10a1 + 100a2 ) + 1000(a3 + a4 10 + a5 102 ) +
10002 (a6 + a7 10 + a8 102 ) + · · ·
≡ (a0 + 10a1 + 100a2 ) − (a3 + a4 10 + a5 102 ) +
(a6 + a7 10 + a8 102 ) − · · ·
(mod 1001)
≡ (a2 a1 a0 )10 − (a5 a4 a3 )10 ) +
(a8 a7 a6 )10 − · · ·
(mod 1001).
So for any of the prime divisors (7, 11, and 13) of 1001, the above says that
n is divisible by the prime iff the alternating sum of triple digits, as in the
theorem, is so divisible.
We give one more result, which provides a general test for divisibility by any
integer d which is relatively prime to 10.
Theorem. Let e be an inverse of 10 modulo d. Let n = (ak ak−1 · · · a2 a1 a0 )10
and put n0 = (n − a0 )/10 + ea0 . Then n is divisible by d iff n0 is divisible by
d.
The proof is an exercise.
To apply the theorem, form the decreasing sequence n, n0 , n00 = (n0 )0 , . . .
until you get to a number small enough to be tractable.
For example, we develop a divisibility test for divisibility by d = 17. We can
take e = −5 since 10 · (−5) ≡ 1 (mod 17). Thus our reduction is
n0 =
n − a0
− 5a0 .
10
Let’s apply this to test n = 1419857 for divisibility by 17. We get by the
rule above that n0 = 141985 − 5 · 7 = 141950, n00 = 14195 − 5 · 0 = 14195,
3
n000 = 1419−5·5 = 1394, n(4) = 139−5·2 = 119, and n(5) = 11−5·9 = −34.
Since −34 is plainly divisible by 17, we see that n = 1419857 is divisible by
17, too.
Note that n(4) = n0000 means an n with 4 ticks after it, and so on.
4