# Why these two solutions are always equal?

This is the problem : repeatedly add all its digits until the result has only one digit.

given the arbitrary number : 96491

This is the first solution that is pretty straight forward and I can understand. The result is $2$.

$(9+6+4+9+1 = 29) => (2+9 = 11) => (1+1 = 2) => 2$

Now here is another solution that I don't understand why it works.

$(9649 + 1 = 9650) => (965 + 0 => 965) => (96 + 5 = 101) => (10+1 = 11) => (1 +1 = 2) => 2$

What just happened? as you see the steps and results during steps seems completely different. yet they always produce same result. this number was just example. it works for any given positive number (tested with program for millions of different numbers). I'm really curios why second solution works? Thanks for explanations.

• haha downvote xD , I know it may be stupid. but I'm really noob at math! thanks :) – M.kazem Akhgary Jan 14 '17 at 10:43
• In terms of common computing operations, what you get if you repeatedly add the digits of a positive integer $n$ until you have a single digit left will always be (n - 1)%9 + 1, no matter what order you do it in. – Arthur Jan 14 '17 at 10:52

The remainder modulo $9$ does not change if we replace any number by the sum of its digits, this can be easily seen : If we have $$N=a_k\cdot 10^k+a_{k-1}\cdot 10^{k-1}+\cdots+a_1\cdot 10+a_0$$ then we have $$N\equiv a_k+a_{k-1}+\cdots +a_1+a_0\mod 9$$ because of $$10^n\equiv 1\mod 9$$ for every non-negative integer $n$.
The final result is $N\mod 9$ , if $N$ is not divisible by $9$ and $9$ , if $N$ is divisble by $9$. As Arthur pointed out, the formula $$((N-1)\mod 9)+1$$ covers all cases.