• it/its

// the deer!
// plural deer therian θΔ, trans demigirl
// stray pet with a keyboard
// i'm 20 & account is 18+!
name-color: #ebe41e
// yeah



lexyeevee
@lexyeevee

click through for a brief proof, which generally assumes a number of the form ...dcba being expressed as x = a + 10b + 100c + 1000d + ... (which is backwards, with the ones digit first, but that's so an arbitrarily long number can be handwaved with dotdotdot). the secret ingredient is that we can add or subtract whatever multiples of N we want, without affecting divisibility by N.

these generally work by reducing the number to a smaller number that is congruent mod N; thus if the smaller number is divisible by N, the original is too. but that means these tests are more powerful than they appear — you can also use every single one of them to determine the remainder when dividing a number by N. for example, 196 is not divisible by 3; the rule has you add the digits, which gives 16. but 16 is 1 more than a multiple of 3 (3×5 + 1), and thus so is 196 (3×65 + 1).

caveats:

  • if you end up with a negative number then you'll have to add some multiples of N to get an appropriate remainder

  • some of the later rules (7, 13, and others following a similar pattern) produce a multiple of the remainder. for example, testing if 15 is divisible by 7 produces -9. to get the remainder, we need to divide by -2. -9 is odd, but we can add or subtract multiples of 7 all we like, so add 7 to get -2, then divide by -2 to get 1, which is the actual remainder. (you can equivalently divide by 5, because 5 and -2 are equivalent mod 7, but a multiple of -2 is easier to find. modular arithmetic is cool.)

the interesting ones are primes and powers of primes; divisibility by anything else can be broken down into testing divisibility of its prime powers, e.g. a number is divisible by 24 iff it is divisible by both 3 and 8.

remember, to fully factor a number, you need only check primes up to its square root.

bonus fact: perfect squares never end in 2, 3, 7, or 8. fourth powers only end in 0, 1, 5, or 6. fifth powers have the same final digit as the original number.


1 — always true.
basic property of 1 as the multiplicative identity
2 — check if last digit is divisible by 2.
a + 10b + 100c + ... = a + 2 × (5b + 50c + ...) ≡ a (mod 2)
3 — check if sum of digits is divisible by 3. recurse if necessary.
a + 10b + 100c + ... = (a + b + c + ...) + 3 × (3b + 33c + ...) ≡ a + b + c + ... (mod 3)
4 — check if last two digits are divisible by 4. subtract multiples of 20 if that helps.
a + 10b + 100c + 1000d + ... = a + 10b + 4 × (25c + 250d + ...) ≡ a + 10b (mod 4)
5 — check if last digit is divisible by 5.
a + 10b + 100c + ... = a + 5 × (2b + 20c + ...) ≡ a (mod 5)
6 — check if divisible by both 2 and 3.
composite
7 — double the last digit and subtract from the rest of the number. check if result is divisible by 7. recurse if necessary. (divide by -2 or 5 to get remainder.)
this is actually a divisibility test for -2 times the original number. but because 7 is prime, if -2x is divisible by 7, then x must be divisible by 7. so: -2x = -2a - 20b - 200c - 2000d - ... ≡ -2a - 20b + 21b - 200c + 210c - 2000d + 2100d - ... (mod 7) = -2a + b + 10c + 100d + ... which is the number we produce.
7 — multiply the last digit by 5 (add a 0 and halve it) and add to the rest of the number. check if result is divisible by 7. recurse if necessary. (divide by 5 or -2 to get remainder.)
this is equivalent to the above, just negative rather than positive. (note the conspicuous -2 vs +5.) which one works better for your brain is up to you. the key to all of these is just to find a multiple of N that ends in a 1 or a 9. 21 is a multiple of 7, so you multiply by 2 and subtract. 49 is a multiple of 7, so you multiply by 5 and add. 5x = 5a + 50b + 500c + 5000d + ... = 5a + (49b + b) + (490c + 10c) + (4900d + 100d) + ... ≡ 5a + b + 10c + 100d + ... (mod 7)
8 — check if last three digits are divisible by 8. subtract multiples of 40 or 200 if that helps.
a + 10b + 100c + 1000d + 10000e ... = a + 10b + 100c + 8 × (125d + 1250e + ...) ≡ a + 10b + 100c (mod 8)
9 — check if sum of digits is divisible by 9. recurse if necessary.
a + 10b + 100c + ... = (a + b + c + ...) + 9 × (b + 11c + ...) ≡ a + b + c + ... (mod 9)
10 — check if last digit is divisible by 10.
a + 10b + 100c + ... = a + 10 × (b + 10c + ...) ≡ a (mod 10)
11 — add up alternating digits, i.e. digits in odd positions and digits in even positions. check if the difference is divisible by 11. (to get the correct remainder, do (ones group) - (tens group). otherwise you'll get the negative of the remainder. for divisibility, it doesn't matter.)
note that 100...1 is always divisible by 11, as long as the number of zeroes is even. you can see this by subtracting 11 once, i.e. 1001 - 11 = 990 = 11 × 90. thus: a + 10b + 100c + 1000d + 10000e + 100000f + ... = a + 10b + (99c + c) + (990d + 10d) + (9999e + e) + (99990f + 10f) + ... = a + 10b + (11 × 9c + c) + (11 × 90d + 10d) + (11 × 909e + e) + (11 × 9090f + 10f) + ... ≡ a + 10b + c + 10d + e + 10f + ... (mod 11) ≡ a + 10b - 11b + c + 10d - 11d + e + 10f - 11f + ... (mod 11) ≡ a + (10b - 11b) + 99c + c + (1000d - 1001d) + 9999e + e + (100000f - 100001f) + ... (mod 11) = a - b + c - d + e - f + ... = (a + c + e + ...) - (b + d + f + ...) an equivalent method is to alternatingly add and subtract the digits, as seen on the second to last line, but i find that makes it easy to lose track of which i'm doing.
12 — check if divisible by both 3 and 4.
composite
13 — multiply the last digit by 4 and add to the rest of the number. check if result is divisible by 13. recurse if necessary. it may help to know that 52 and 104 are multiples of 13. (divide by 4 or -9 to get remainder.)
analogous to 7: 4x = 4a + 40b + 400c + 4000d + ... = 4a + (39b + b) + (390c + 10c) + (3900d + 100d) + ... ≡ 4a + b + 10c + 100d + ... (mod 13)
14 — check if divisible by both 2 and 7.
composite
15 — check if divisible by both 3 and 5.
composite
16 — check if last four digits are divisible by 16. subtract multiples of 80, 400, or 2000 if that helps.
a + 10b + 100c + 1000d + 10000e ... = a + 10b + 100c + 1000d + 16 × (625e + ...) ≡ a + 10b + 100c + 1000d (mod 16)
16 — add the last two digits and four times the next two digits. check if result is divisible by 16.
this is the same idea but knocks out multiples of 96, which might be helpful if you don't know your 16 times tables all the way up to ten thousand: a + 10b + 100c + 1000d + 10000e ... = a + 10b + 100c + 1000d + 16 × (625e + ...) = a + 10b + (96c + 4c) + (960d + 40d) + 16 × (625e + ...) = a + 10b + 4 × (c + 10d) + 16 × (6c + 60d + 625e + ...) ≡ a + 10b + 4 × (c + 10d) (mod 16)
17 — multiply the last digit by 5 and subtract from the rest of the number. check if result is divisible by 17. recurse if necessary. it may help to know that 51 and 102 are multiples of 17. (divide by 5 or -12 to get remainder.)
analogous to 7: -5x = -5a - 50b - 500c - 5000d - ... = -5a + (-51b + b) + (-510c + 10c) + (-5100d + 100d) + ... ≡ -5a + b + 10c + 100d + ... (mod 17)
18 — check if divisible by both 2 and 9.
composite
19 — double the last digit and add to the rest of the number. check if result is divisible by 19. recurse if necessary. it may help to know that 95 is a multiple of 19. (divide by 2 to get remainder.)
analogous to 7: 2x = 2a + 20b + 200c + 2000d + ... = 2a + (19b + b) + (190c + 10c) + (1900d + 100d) + ... ≡ 2a + b + 10c + 100d + ... (mod 19)
20 — check if divisible by both 4 and 5.
composite
21 — check if divisible by both 3 and 7.
composite
22 — check if divisible by both 2 and 11.
composite
23 — multiply the last digit by 7 and add to the rest of the number. check if result is divisible by 23. recurse if necessary. it may help to know that 69 and 299 are multiples of 23. (divide by 7 to get remainder.)
analogous to 7: 7x = 7a + 70b + 700c + 7000d + ... = 7a + (69b + b) + (690c + 10c) + (6900d + 100d) + ... ≡ 7a + b + 10c + 100d + ... (mod 23)
24 — check if divisible by both 3 and 8.
composite
25 — check if last two digits are divisible by 25.
a + 10b + 100c + 1000d + ... = a + 10b + 25 × (4c + 40d + ...) ≡ a + 10b (mod 25)
26 — check if divisible by both 2 and 13.
composite

at this point i was musing over a better rule for 27 when i discovered that wikipedia just has a fucking table all the way up to 30 including a bunch of alternative rules i've never even heard of so i guess this was a huge waste of time!


You must log in to comment.

in reply to @lexyeevee's post:

Another (albeit more computationally-intensive) way is to difference the base-b interpretation of a number with the base-t interpretation. The difference between those two interpretations will always be divisible by b-t, so if the base-t interpretation is divisible by b-t, then so is the number. Eg 231 - the base-3 interpretation (11 + 33 + 2*9 = 28) -> 231 is divisible by 7.

just because the answers are already printed in the back of the book, doesn't make the exercises a waste of time! i had my divisibility tests era in high school and imo it taught me a lot about what it means to solve problems.

here are my notes for a general divisibility test in base 10, i.e. can you divide 10x + y by n:

  • tests and division for 2 and 5 are easy imo, so get rid of those factors from divisor and dividend. now wlog n = 10k ± 1 or 10k ± 3.
  • optionally factor n into coprimes: the test for n = ab is the conjunction of the tests for coprime a and b.
  • 10x + y is divisible by n = 10k ± 1 iff xky is.
  • 10x + y is divisible by n = 10k ± 3 iff x ± (3k ± 1)y is.

Fun facts:

The rule for 7, 11, and 13 that I know is "alternate-sum every block of 3 digits" (because 1,001 = 7 x 11 x 13). Once you get to 3 digits or less, you can then use another rule or compute it directly.

The rule for 3 is basically in the same form as the rest: "Add (1 times) the last digit to the rest of the number and recurse".