[Math] Why is $((n-1) \mod 9)+1$ equal to summing all digits till one digit is left

summation

There was a question on SO on how to, in excel, sum all digits in a number until you are left with one single digit. The correct answer, in excel format, turns out to be =1+MOD(A1-1,9) which I wrote as $((n-1) \mod 9)+1$. I tried this it out with several numbers,

  • n=123 : $1+2+3 = 6$ and $((123-1) \mod 9)+1 = 6$
  • n=456 : $4+5+6 = 15, 1+5 = 6$ and $((465-1) \mod 9)+1 = 6$
  • n=8910 : $8+9+10 = 27, 2+7 = 9$ and $((8910-1) \mod 9)+1 = 9$

Now I try to understand the relationship between summing all the numbers and simply using the formula $((n-1) \mod 9)+1$. Why are these two always equal?

Best Answer

The sum of the digits in any number is congruent to that number modulo $9$. To see why it holds write the number $\overline{z...cba}$, as $a\cdot10^0 + b\cdot 10^1 +...$ and use the fact that the $10 \equiv 1 \pmod 9$. Repeating this step will not change the remainder modulo 9, so eventually we will get a number between $1$ and $9$, as $0$ is impossible.

On the other hand we get that $((n-1) \mod 9) + 1$ gives us the remainder of $n$ when divided by $9$. The trick when we first subtract $1$ and add it at the end ensures that we'll get a number between $1$ and $9$, rather than in the congruence class of $9$, which is from $0$ to $8$. In other words you calculate the remainder of $n-1$ modulo 9 and then you just add $1$ as the remainders between $n$ and $n-1$ differ by 1.

Related Question