1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Note that $10\equiv 1 \pmod 9$. What does this say about, say, $8*10^3+9*10^2+1*10^1+0\pmod{9}? $ $\endgroup$ – Nathan Weckwerth May 17 '16 at 21:27
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Once again I have problems with English syntax and I take long to write a solution. I wanted generalize to subtract not only $1$ but also any digit and comes out the same. And I suspect it may even be replaced $1$ by any other integer not only the first 8 digits. $\endgroup$ – Piquito May 17 '16 at 22:30
  • $\begingroup$ @Piquito if we replace 1 by any other integer than the formula will output numbers of the set $\{k,k+1,...,k+8\}$, which is not necessarily a one digit number. Actually we can see that only $k=1$ works $\endgroup$ – Stefan4024 May 17 '16 at 22:36
  • $\begingroup$ Hi Stefan: Look at this:(1) $439\to 439-5=434=48\cdot 9+2\to 2+5=7$. Now $4+3+9=16\to 1+6=7$. (2) $747\to747-8=739=82\cdot 9 +1\to 1+8=9$. Now $7+4+7=18\to 1+8=9$. You can verify the question with other values. Regards. $\endgroup$ – Piquito May 17 '16 at 22:55
  • $\begingroup$ @Piquito what about 39? We have $39 \to 3+9 = 12 \to 1+2 = 3$. On the other hand $((39-5) \mod 9) + 5 = 7 + 5 = 12$, but the results are different. Obviously they are congruent modulo 9 always, but this defeats the purpose of subtracting 1 at the beginning and adding it later, as we want to get the same number, not number that are congruent mod 9, but not necessarily same $\endgroup$ – Stefan4024 May 17 '16 at 23:00
  • $\begingroup$ I understand now what you say. However the residue must be of one digit and $1+2=3$. For a generalization it remains an easy additional detail. Finally let's get this. Thank you very much. $\endgroup$ – Piquito May 17 '16 at 23:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.