Number TheoryCongruences

Divisibility Tests from Congruences

Since 10 ≡ 1 (mod 9) and 10 ≡ −1 (mod 11), digit sums and alternating digit sums test divisibility by 9 and by 11.

Not started Jump to practice

You may know that a number is divisible by 9 when its digit sum is. With modular arithmetic this stops being a trick and becomes a two-line proof, and the same idea gives tests for 3, 11, 4, 8 and even 7 and 13.

Why it works

Write $n = d_k 10^{k} + \cdots + d_1 10 + d_0$ in base 10. Since $10 \equiv 1 \pmod{9}$, every power $10^{i} \equiv 1$, so $$n \equiv d_k + \cdots + d_1 + d_0 \pmod{9}.$$ The same holds mod $3$. Since $10 \equiv -1 \pmod{11}$, the powers $10^{0}, 10^{1}, 10^{2}, \dots$ are $\equiv 1, -1, 1, \dots$, so $$n \equiv d_0 - d_1 + d_2 - d_3 + \cdots \pmod{11},$$ with the signs starting at the ones digit.
Each test is one congruence about a power of 10. They give the remainder, not just a yes or no.
ModulusBecauseTest
3, 9$10 \equiv 1$digit sum
11$10 \equiv -1$alternating sum from the right
2, 5$10 \equiv 0$last digit
4$100 \equiv 0$last two digits
8$1000 \equiv 0$last three digits
7, 11, 13$1000 \equiv -1$ (as $1001 = 7 \cdot 11 \cdot 13$)alternating sum of 3-digit blocks

Worked example: Remainder mod 9

Find the remainder of $8{,}437{,}265$ divided by $9$.
  1. Digit sum: $8 + 4 + 3 + 7 + 2 + 6 + 5 = 35$.
  2. $35 \equiv 3 + 5 = 8 \pmod{9}$.

Answer: $8$.

Worked example: Divisible by 11?

Is $918{,}082$ divisible by $11$?
  1. From the ones digit: $2 - 8 + 0 - 8 + 1 - 9 = -22$.
  2. $-22 \equiv 0 \pmod{11}$, so yes. Indeed $918{,}082 = 11 \cdot 83{,}462$.

Answer: Yes.

Worked example: A missing digit

The 6-digit number $7\square4312$ is divisible by 11. Find the missing digit.
  1. From the right: $2 - 1 + 3 - 4 + \square - 7 = \square - 7$.
  2. We need $\square - 7 \equiv 0 \pmod{11}$, and the only digit that works is $\square = 7$.
  3. Check: $774{,}312 = 11 \cdot 70{,}392$.

Answer: $7$.

Worked example: Blocks of three for 7

Find the remainder of $2{,}456{,}789$ divided by $7$.
  1. Since $1001 = 7 \cdot 143$, we have $1000 \equiv -1 \pmod{7}$. So group the digits in threes from the right and alternate signs: $789 - 456 + 2 = 335$.
  2. $335 = 7 \cdot 47 + 6$, so the remainder is $6$. Check: $2{,}456{,}789 = 7 \cdot 350{,}969 + 6$.

Answer: $6$.

Common mistake

Starting the alternating sum from the leftmost digit when you want the remainder mod 11. For $4316$: from the right, $6 - 1 + 3 - 4 = 4$, the true remainder ($4316 = 11 \cdot 392 + 4$). From the left, $4 - 3 + 1 - 6 = -4 \equiv 7$, the negative of it. (The two agree when the number has an odd number of digits, or when the answer is 0.) Always give the ones digit the plus sign.
Casting out nines is an old way to check arithmetic: since every number is congruent to its digit sum mod 9, the digit sum of a correct product must match the product of the digit sums, mod 9. It catches most slips, though not swapped digits.

Key idea

A divisibility test is a congruence for a power of 10: $10 \equiv 1 \pmod{9}$ gives digit sums, and $10 \equiv -1 \pmod{11}$ gives alternating sums from the ones digit.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Number Theory.

Sources and further reading

  • William Stein, Elementary Number Theory: Primes, Congruences, and Secrets (Springer, 2009; free online edition), chapter 2, The Ring of Integers Modulo n
  • Lehman, Leighton and Meyer, Mathematics for Computer Science (MIT OpenCourseWare 6.042J), chapter on number theory: modular arithmetic
@teddyrookbook GitHub