[Math] Proving a particular divisibility rule for 7

modular arithmetic

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.

Best Answer

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$.

Related Question