where each digit di∈{0,1,…,9}. Also recall that congruences respect addition and multiplication; if we reduce everything mod n, the digits stay exactly where they are and only the powers of 10 change. This gives us the master congruence that every test in this lecture falls out of:
N≡dk(10kmodn)+⋯+d1(10modn)+d0(modn).
Basically, to test divisibility by n we never need to actually divide by n; we only need to know how the powers of 10 behave mod n. There are three behaviours worth knowing:
10i≡0(modn) from some point onwards (this happens exactly when n divides a power of 10, i.e. n=2a5b); then only the last few digits matter.
10≡1(modn) (this is n=3 or 9); then every power of 10 is 1 and we just sum the digits.
10≡−1(modn) (this is n=11); then the powers alternate between 1 and −1 and we alternately add and subtract digits.
For everything else (like 7 and 13), the powers of 10 cycle through junk values, so we cheat: we multiply the number by a carefully chosen constant first so that a nice pattern appears. Divisibility tests like these matter because they replace division (which is expensive to do in your head) with addition, subtraction and truncation, and they let you sniff out prime factorisations quickly.
Lemma (powers of 2)
An integer is divisible by 2k if and only if the number formed by its last k digits is divisible by 2k.
Note
Lemma (powers of 5)
An integer is divisible by 5k if and only if the number formed by its last k digits is divisible by 5k.
Basically, 2 and 5 are the prime factors of 10, so high enough powers of 10 absorb any power of 2 or 5; everything past the last k digits is invisible mod 2k and mod 5k, so you can just throw it away.
Proof. Split N into the part before and after its last k digits;
N=(dj⋯dk)10×10k+(dk−1⋯d1d0)10=M×10k+L, where L is the number formed by the last k digits.
Since 10k=2k5k, we have 2k∣10k, i.e. 10k≡0(mod2k). Reducing mod 2k,
N≡M×0+L(mod2k), (as 10k≡0)≡L(mod2k).
Therefore 2k∣N if and only if 2k∣L. The exact same argument with 5k∣10k proves the second lemma. ■
The small cases are the ones you use constantly:
2: last digit is even,
4: last two digits divisible by 4,
8: last three digits divisible by 8,
5: last digit is 0 or 5,
10: last digit is 0 (since 10=2×5, this is really the 2 test and the 5 test at once).
The tests for 2, 5 and 10 are basically primary school stuff so I'm not gonna dwell on them.
Example. Which powers of 2 and 5 divide 123450?
Work through the last digits one layer at a time;
last digit: last two digits: last three digits: 0,50=4(12)+2,50=25(2),450=125(3)+75,so 2∣123450 and 5∣123450,so 4∤123450,so 25∣123450,so 125∤123450.
Notice how once 4 fails there is no point testing 8; if 8∣N then 4∣N, so the powers of 2 stop dead at the first failure. Therefore, the only powers dividing 123450 are 21 and 51,52; in fact 123450=2×3×52×823.
Example. Find the largest power of 2 dividing 2,345,678,000.
The lemma works for any k, not just the k≤3 in the standard table; we keep grabbing one more digit until the test fails.
last three digits: 000last four digits: 8000last five digits: 78000=0,=16(500),=32(2437)+16,so 8∣N (every number divides 0),so 16∣N,so 32∤N.
Therefore, the largest power of 2 dividing 2,345,678,000 is 24=16. It is important to note that trailing zeros hand you factors for free: three trailing zeros means 103=2353 divides the number immediately, and you only have to do real work from the fourth digit onwards.
Lemma (divisibility by 3)
An integer is divisible by 3 if and only if the sum of its digits is divisible by 3.
Note
Lemma (divisibility by 9)
An integer is divisible by 9 if and only if the sum of its digits is divisible by 9.
This is the famous digit-sum test, and the reason it works is one line of modular arithmetic: 10≡1(mod9), so every power of 10 is congruent to 1, and each digit just contributes itself.
Proof. Let N=(dk⋯d1d0)10. Since 10≡1(mod9), we have 10i≡1i=1(mod9) for every i (congruences respect multiplication, so we may raise both sides to the ith power). Then
N=dk×10k+⋯+d1×10+d0≡dk×1+⋯+d1×1+d0(mod9), (replacing each 10i by 1)≡dk+dk−1+⋯+d1+d0(mod9).
So N is congruent to its own digit sum mod 9; in particular 9∣N if and only if 9 divides the digit sum. Since 10≡1(mod3) as well, the identical argument works mod 3. ■
Notice that the proof gives us something strictly stronger than the lemma;
N≡dk+dk−1+⋯+d1+d0(mod9) and (mod3).
The digit sum doesn't just tell you whether9∣N; it tells you the actual remainder. You can also iterate; if the digit sum is still big, take the digit sum of the digit sum, since the congruence keeps holding.
Example. Which of 123450 and 12345678 are divisible by 3 or by 9?
For 123450,
1+2+3+4+5+0=15=3(5),
so 3∣123450, but 9∤15 so 9∤123450; in fact 123450≡15≡6(mod9).
For 12345678,
1+2+3+4+5+6+7+8=36=9(4),
so 9∣12345678, and hence automatically 3∣12345678 too. Therefore, 123450 is divisible by 3 only, while 12345678 is divisible by both 3 and 9.
Because N is congruent to its digit sum mod 9 (not just "divisible iff divisible"), we can use the digit-sum lemma to sanity-check arithmetic: any correct equation in Z must still be a correct congruence in Z9, and digit sums make working mod 9 nearly free. This trick is called casting out nines.
Example. A friend claims that 6437+2895=9342. Check the claim by casting out nines.
Reduce everything mod 9 using digit sums;
Since 8≡0(mod9), the claimed answer is wrong without us ever doing the addition. Therefore, the sum cannot be 9342; the true answer is 9332, which indeed satisfies 9+3+3+2=17≡8(mod9).
It is important to remember that casting out nines can only ever prove an answer wrong; a passed check does not prove the answer right, and it will never catch a mistake that swaps two digits, because swapping digits does not change the digit sum. For digit swaps you need the mod 11 test below, where position actually matters.
Lemma (divisibility by 11)
An integer is divisible by 11 if and only if the result of alternately adding and subtracting its digits is divisible by 11.
The mechanism is the mirror image of the digit-sum test: this time 10≡−1(mod11), so the powers of 10 flip sign at every position, i.e. 10i≡(−1)i(mod11).
Proof. Let N=(dk⋯d1d0)10. Since 10≡−1(mod11), we have 10i≡(−1)i(mod11), so
Hence 11∣N if and only if 11 divides the alternating sum of the digits. ■
Basically, the even-position digits (units, hundreds, ...) count positively and the odd-position digits (tens, thousands, ...) count negatively. If you start the alternation from the leftmost digit instead you might get the negative of this sum, which makes no difference to divisibility, but if you want the actual remainder mod 11 you must start from the units digit with a plus sign.
Example. Which of 123450 and 1234321 are divisible by 11?
For 123450, starting from the units digit,
0−5+4−3+2−1=−3,
and 11∤−3, so 11∤123450 (in fact 123450≡−3≡8(mod11)).
For 1234321,
1−2+3−4+3−2+1=0,
and every number divides 0, so 11∣1234321. Therefore, only 1234321 is divisible by 11; unsurprising once you notice 1234321=11112 and 11∣1111.
Here is the follow-up to casting out nines: transposition errors are invisible mod 9 but visible mod 11, since the alternating sum cares which position each digit sits in. Checking mod 9and mod 11 together is a genuinely strong error check.
Example. A friend claims that 8734×56=489140. Check the claim mod 9 and mod 11.
First cast out nines;
Since 3≡0(mod11), the claim is false. Therefore, the product cannot be 489140; the true answer is 489104 (the last two digits were swapped), and you can check its alternating sum is 4−0+1−9+8−4=0 as required.
Lemma (divisibility by 7)
An integer is divisible by 7 if and only if the result of removing its last digit and subtracting 2 times that digit is divisible by 7.
In symbols: write N=10a+b where b is the last digit and a is the rest of the number; then 7∣N if and only if 7∣a−2b. You apply this repeatedly, shrinking the number by one digit each time, until it is small enough to eyeball.
Why does this work? The powers of 10 mod 7 cycle through 3,2,6,4,5,1 — no nice pattern — so no digit-sum-style test exists. The trick from the lectures: look for a small multiple of 7 that sits next to a multiple of 10. We find 21=2×10+1, so 20≡−1(mod7), and multiplying N by 2 makes everything collapse.
Since 7∣7, we conclude 7∣97531 (indeed 97531=7×13933). Therefore, only 97531 is divisible by 7. You could also have stopped at 91 if you recognised 91=7×13; stop as soon as you can see the answer.
Unlike the digit-sum test, this test does not preserve remainders; it only preserves whether the remainder is zero. For example, take N=16: the test gives 1−2(6)=−11≡3(mod7), but 16≡2(mod7). The culprit is that we multiplied by 2 along the way, which scrambles every nonzero residue while fixing 0. So use this for yes/no questions only; if an exam question wants Nmod7, do it directly.
Lemma (divisibility by 13)
An integer is divisible by 13 if and only if the result of removing its last digit and adding 4 times that digit is divisible by 13.
Same idea as for 7: we hunt for a small multiple of 13 adjacent to a multiple of 10, and this time 39=4×10−1 works, giving 40≡1(mod13).
Proof. Let N=10a+b. Multiplying by 4,
4N=40a+4b≡a+4b(mod13), (as 40=39+1≡1).
Since gcd(4,13)=1, we get 13∣N⟺13∣4N⟺13∣a+4b. ■
Example. Which of 12345 and 12389 are divisible by 13?
For 12345, repeatedly remove the last digit and add four times it;
1234+4(5)125+4(4)14+4(1)=1254,=141,=18.
Since 13∤18, we conclude 13∤12345.
For 12389,
1238+4(9)127+4(4)14+4(3)=1274,=143,=26.
Since 26=13×2, we conclude 13∣12389 (indeed 12389=13×953). Therefore, only 12389 is divisible by 13. The same remainder warning applies here: because we multiplied by 4, the final number 26 tells you nothing about Nmod13 beyond the fact that it is 0.
What about 6, 12, 15, and friends? We do not need new tests; we split the modulus into pieces we already know how to test, provided the pieces share no common factor.
Note
Proposition (coprime factors)
Let m,n be integers with gcd(m,n)=1. Then for any integer N,
mn∣N⟺m∣N and n∣N.
Proof. (⇒) If mn∣N, then since m∣mn and n∣mn, transitivity of divisibility (Lemma 1.2 in Divisibility and Primes) gives m∣N and n∣N.
(⇐) Suppose m∣N and n∣N, so N=mk for some k∈Z. Then n∣mk, and since gcd(n,m)=1, n has no factors in common with m, so n must divide k; write k=nℓ. Then N=mnℓ, so mn∣N. ■
Basically, a number is divisible by 6 exactly when it passes the 2 test and the 3 test, and divisible by 12 exactly when it passes the 4 test and the 3 test.
You must split into coprime pieces; being divisible by 4 and by 6 does not make a number divisible by 24, because gcd(4,6)=2=1. For example, 612 is divisible by 4 (last two digits 12) and by 6 (even, digit sum 9), yet 612=24×25+12, so 24∤612. The correct split is 24=8×3; the last three digits give 612=8×76+4, so the 8 test fails and 24∤612, as expected.
Example. Is 123450 divisible by 6? Is 12345678 divisible by 12?
For 6=2×3 (coprime pieces): 123450 ends in 0, so 2∣123450; its digit sum is 15, so 3∣123450. Both tests pass, therefore 6∣123450.
For 12=4×3 (coprime pieces): the digit sum of 12345678 is 36, so 3∣12345678; but the last two digits give
78=4(19)+2,
so 4∤12345678. Therefore 12∤12345678, even though it is divisible by 9; one failed piece is enough to kill the whole test.
Example. Is 40,740,711 divisible by 33? By 99?
Since 33=3×11 and gcd(3,11)=1, we run the 3 test and the 11 test and combine them using the coprime factor proposition.
Digit sum:
4+0+7+4+0+7+1+1=24=3(8),
so 3∣40740711, but 9∤24 so 9∤40740711.
Alternating sum (units digit first):
1−1+7−0+4−7+0−4=0,
so 11∣40740711. Both the 3 test and 11 test pass, therefore 33∣40740711 (in fact 40740711=33×1234567). However 99=9×11 needs the 9 test to pass, and it fails; therefore 99∤40740711. Notice how one digit sum and one alternating sum settled divisibility by 3,9,11,33 and 99 all at once; this is why you factorise the modulus first instead of long-dividing.
The tests for 7 and 13 came from one recipe, and the lecture notes point out it generalises: for any prime p other than 2 and 5, look for a small multiple of p that is one more or one less than a multiple of 10. We can package the whole recipe as a proposition.
Note
Proposition (build-your-own truncation test)
Let p be a prime with gcd(p,10)=1, and suppose 10m≡ε(modp) for some integer m and ε∈{1,−1}. Then for any integer N=10a+b with last digit b,
Now p∤m (otherwise 10m≡0≡±1(modp)), so multiplying by m preserves divisibility by p; and multiplying by ε=±1 obviously does too. Hence p∣N⟺p∣mN⟺p∣a+εmb. ■
Sanity check against what we already have: for p=7, 21≡0 gives 10(2)≡−1, so m=2, ε=−1 and the test is a−2b; for p=13, 39≡0 gives 10(4)≡1, so m=4, ε=1 and the test is a+4b. Both match the lemmas above.
Example. Build a truncation test for 17, and use it to decide whether 17∣2023.
We want a multiple of 17 next to a multiple of 10; 51=3×17 works, since 51=50+1 gives
5010(5)≡−1(mod17)≡−1(mod17),
so m=5, ε=−1: remove the last digit and subtract 5 times it. Applying this to 2023;
202−5(3)18−5(7)=187,=−17.
Since 17∣−17, we conclude 17∣2023. Therefore 2023 is divisible by 17; indeed 2023=7×172. (Negative outputs are fine; divisibility doesn't care about sign.)
Example. Build a truncation test for 19, and use it to decide whether 19∣2261.
Here 19 itself is one less than 20, so
2010(2)≡1(mod19)≡1(mod19),
giving m=2, ε=1: remove the last digit and add 2 times it. Applying this to 2261;
226+2(1)22+2(8)=228,=38.
Since 38=19×2, we conclude 19∣2261. Therefore 2261 is divisible by 19; indeed 2261=19×119.
The digit-sum idea also generalises: instead of asking how 10 behaves mod p, ask how 10k behaves for small k. If 10k≡1(modp), then chopping N into blocks of k digits (from the right) and summing the blocks preserves the value of N mod p — exactly the digit-sum proof with 10k playing the role of 10. And because we never multiply by anything, block tests preserve remainders, unlike the truncation tests.
Example. Build a test for 37, and use it to decide whether 37∣456765.
Notice 999=27×37, so
103≡1(mod37),
which means every 3-digit block contributes itself: chop into blocks of three and add. For 456765 the blocks are 456 and 765;
456+765=1221=37(33).
Since 37∣1221, we conclude 37∣456765 (indeed 456765=37×12345). Therefore 456765 is divisible by 37. As a bonus, the same fact 999=27×37 gives an identical 3-digit block test for 27; here 1221=27×45+6, so 27∤456765.
Example. Use 1001=7×11×13 to test 12345 for divisibility by 7, 11 and 13 simultaneously.
Since 1001≡0 modulo each of 7,11,13, we get
103≡−1(mod7),(mod11) and(mod13),
so the 3-digit blocks alternate in sign, just like the 11 test but with blocks instead of digits. For 12345 the blocks from the right are 345 and 12;
345−12=333.
Now reduce 333 by each prime: 333=7(47)+4, so 12345≡4(mod7); 333=11(30)+3, so 12345≡3(mod11); 333=13(25)+8, so 12345≡8(mod13). Therefore 12345 is divisible by none of 7, 11 or 13 — and notice how the mod 7 and mod 13 remainders here are the actual remainders, consistent with (and more informative than) the truncation tests we ran on 12345 earlier. For a satisfying yes-instance, take 999999: its blocks give 999−999=0, so 999999 is divisible by 7, 11 and 13 all at once.
So when you're handed an unfamiliar divisor on an exam, the decision goes:
n=2a5b: look at the last max(a,b) digits.
n∈{3,9,11} (or you want a remainder cheaply): digit sums and alternating sums.
n composite: factorise into coprime prime powers and test each piece.
n some other prime: find a multiple of n near a multiple of 10 for a quick yes/no truncation test, or a power 10k≡±1(modn) if you also want remainders.
Removing last digit and subtracting 2 times that digit is divisible by 7.
8
Last 3 digits is divisible by 8.
9
Sum of digits is divisible by 9.
10
Last digit is 0 (divisible by both 2 and 5).
11
Alternating signed sum of digits is divisible by 11.
12
Divisible by 4 and by 3.
13
Removing last digit and adding 4 times that digit is divisible by 13.
Tests for primes (or prime powers) beyond 13 are built exactly as in the previous section: seek small multiples of the prime that are 1 more or 1 less than a multiple of 10, or a small power of 10 that is ±1 mod the prime.