Let $S(n)$ be the sum of digits of $n$.
Numerically, I've found that for all $n$ where $S(n) = S(n^2)$, $n \equiv 0,1 \bmod 9$.
Why is that? Is there a proof to show that this is always the case?
Let $S(n)$ be the sum of digits of $n$.
Numerically, I've found that for all $n$ where $S(n) = S(n^2)$, $n \equiv 0,1 \bmod 9$.
Why is that? Is there a proof to show that this is always the case?
Good question.
Lets say that $a_k$ is the $k$th digit of $n$ (and let $l+1$ be the number of digits of $n$, so \begin{align} n &= \sum_{k=0}^l a_k \cdot 10^k\\ &= \sum_{k=0}^l a_k + a_k \cdot (10^k -1) \\ &= \sum_{k=0}^l a_k + \sum_0^l a_k \cdot (10^k -1) \\ &= S(n) + \sum_0^l a_k \cdot (10^k -1) \\ \end{align} Note that the seconnd summand can be divided by 9, which means that $n \equiv S(n) \bmod 9$ for every $n \in \mathbb{N}$
Now if $S(n) = S(n^2)$, then \begin{align} 0 &= S(n^2) - S(n)\\ &\equiv n^2 - n\\ &= n \cdot (n-1) \end{align} So when is $n \cdot (n-1)$ divided by $9$? There are 3 solutions: