Why is $((n-1) \mod 9)+1$ equal to summing all digits till one digit is left? 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?
 A: 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.
A: (I saw this topic a long time ago, the formula needs to be proven.
I use Google Translate from Vietnamese.)
Prove that the formula $P_{(s)} = (s - 1) \mod 9 + 1$ finds the sum of one digit of an integer greater than 0 with one or more digits.
Prove:

*

*Let $A$ be the set of integers {$1,2,...,9$}.

*Let $P_{(s)}$ be the sum of one digit of a multi-digit number.

*Based on the formula $P_{(s)} = (s - 1) \mod 9 + 1$, $s > 0$, then $s - 1$ is always $s \ge 0$, so $P_{(s)} € A$.

*Let $a1, a2, a3, ..., an$ be the digits in a number, the value of the set {$0,1,2,...,9$}.

*Let $s$ be a 1 or more digit number.

Me has the general formula of $s$:
\begin{align}
s & = a1*10^0 + a2*10^1 + a3*10^2 + ... + an*10^{n-1}\\
& = a1 + a2*10 + a3*10^2 + ... + an*10^{n-1}\\
& =  a1 + a2 + a2*(10^1-1) + a3 + a3*(10^2-1) + ... + an + an*(10^{n-1}-1 )\\
& = a1 + a2 + a3 + ... + an + a2*9 + a3*99 + ... + an*(10^{n-1}-1 )\\
\end{align}
Let b be the value of the expression $a2*9 + a3*99 + ... + an*(10^{n-1}-1)$, based on the sign of divisibility by 9, b is always divisible by 9.
Let $C_{n}$ be the sum of n numbers, the values ​​obtained are respectively:




$C_{n}$
total value
values




$C_{1}$
a1
$0 \to 1*10-1 = 9*1$


$C_{2}$
a1 + a2
$0 \to 2*10-2 = 9*2$


$C_{3}$
a1 + a2 + a3
$0 \to 3*10-3 = 9*3$


$C_{n}$
a1 + a2 + a3 + ... + an
$0 \to n*10-n = 9*n$




\begin{align}
Cₙ & = a1 + a2 + a3 + ... + an\\
& = a1 + a2*10 + a3*10^2 + ... + an*10^{n-1} - a2*9 - a3*99 - ... - an*(10^{n-1}-1)\\
& =  s - b\\
\end{align}
Conclusion [1] :

*

*when s loses b value, we get a sum of digits

*[2] When n = 1, then $C_{n}$ € A , $s = C_{n}$, $P_{(s)} = (s - 1) \mod 9 + 1$ is always true.

With s:
\begin{align}
s & = C_{n} + b\\
& = (C_{n})_{C_{n}} + b_{C_{n}} + b​\\
& = ((C_{n})_{C_{n}})_{C_{n}} + b_{(C_{n})_{C_{n}}} + b_{C_{n}} + b​\\
& = ...((C_{n})_{C_{n}})_{C_{n}} + b...((C_{n})_{C_{n}})_{C_{n}} + ... + b_{(C_{n})_{C_{n}}} + b_{C_{n}} + b​\\
\end{align}
Let $Z_{m}$ be the sum of $C_{n}$ the expression of the value s, to get [3] the value $Z_{m} € A$ then:
\begin{align}
s = b + bZ_{0} + bZ_{1} + bZ_{2} + ... + bZ_{m-1} + Z_{m}\\
\end{align}
Let B be the value of the expression $b + bZ_{0} + bZ_{1} + bZ_{2} + ... + bZ_{m-1}$ then:
$$s = Z_{m} + B​$$
Based on [1] :
\begin{align}
P_{(s)} & = Z_{m} + B - B\\
& = Z_{m} + B \mod 9​\\
\end{align}
Based on [2] and [3] :
\begin{align}
P_{(s)} & = (Z_{m}-1) \mod 9 + 1 + B \mod 9​\\
& = (Z_{m} + B - 1) \mod 9 + 1​\\
& = (s - 1) \mod 9 + 1​\\
\end{align}
Conclusion Thesis:
The formula $P_{(s)} = (s - 1) \mod 9 + 1$ finds the sum of one digit of an integer greater than 0 with one or more digits.
