I came across this rule of divisibility by 7:

Let N be a positive integer. Partition N into a collection of 3-digit numbers from the right (d3d2d1, d6d5d4, ...).

N is divisible by 7 if, and only if, the alternating sum S = d3d2d1 - d6d5d4 + d9d8d7 - ... is divisible by 7.

I'm trying to prove this rule. Though I'm sure this might be done using modular arithmetic, I haven't reached anything useful. I have searched for a proof and haven't found one. Any idea or hint will be appreciated.

Thanks a lot.

  • $\begingroup$ So, to clarify, for 664123, you would say 664-123 = 541 = 80*70+1, indivisible by 7, so 664123 is indivisible by 7? $\endgroup$ – charlotte Jan 26 '15 at 1:53
  • 2
    $\begingroup$ Note that $7$ divides $1001$, so $1000\equiv -1 \pmod 7$. $\endgroup$ – Rory Daulton Jan 26 '15 at 1:54
  • $\begingroup$ Note also this works mod 11 and mod 13 since $1001=7\cdot 11\cdot 13$ $\endgroup$ – Eleven-Eleven Jan 26 '15 at 2:18
  • $\begingroup$ @Ahmed, See also : math.stackexchange.com/questions/328562/… $\endgroup$ – lab bhattacharjee Jan 26 '15 at 15:22

This is because $10^3\equiv -1 \pmod 7$. Notice that what we're doing when cut up the decimal expansion of a number $n$ like that is saying that, where $a_0$ is the first three digits, $a_1$ is the next, and so on: $$n= a_0+10^3a_1+(10^3)^2a_2+(10^3)^3a_3+\ldots$$ but, looking at this mod $7$ gives $$n\equiv a_0+(-1)a_1 + (-1)^2 a_2 + (-1)^3 a_3+\ldots\pmod 7$$ So, in fact, the alternating sum is congruent to the original number mod $7$.


$$N = \sum_{i=0} A_i 1000^i$$

$$D = \sum_{i=0} A_i (-1)^i$$

We want to prove $N \equiv 0 \pmod 7 \iff D \equiv 0 \pmod 7$, but you can prove the stronger statement:

$$N \equiv D \pmod {7}$$ by $$\sum_{i=0} A_i 1000^i \equiv \sum_{i=0} A_i (-1)^i \pmod 7$$

and as noted by Rory Daulton in the comments, $1000 \equiv -1 \pmod 7$, so the above statement is true.


Let me unroll the process a little more for you.

You have a number say that looks like $d_7d_6d_5d_4d_3d_2d_1$. We can rewrite this as $d_7d_6d_5d_4 \times 1000 + d_3d_2d_1$. Then, because $1001=7\times 143$ we can rewrite the $1000$ as $7\times 143-1$, and the number as $d_7d_6d_5d_4 \times (7\times 143-1) + d_3d_2d_1 = d_7d_6d_5d_4 \times 7\times 143 - d_7d_6d_5d_4 + d_3d_2d_1$.

Now we're only interested in divisibility by 7, so we can ignore the part that is a multiple of seven and just test $ d_3d_2d_1 - d_7d_6d_5d_4 $. And now we can apply the same trick to the last part, and just test $ d_3d_2d_1 - (d_6d_5d_4 -d_7) = d_3d_2d_1 - d_6d_5d_4 + d_7$ - as required.

Note that $1001 =7\times 11\times 13$ so you can actually apply the same trick to test for divisibility by 13. For divisibility by 11 you can use a stronger version of the same technique, testing $ d_1 -d_2 + d_3-d_4 + d_5-d_6 + d_7$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy