Why are all $n$, s.t. the sum of digits of $n$ and $n^2$ coincide, $\equiv 0,1 \bmod 9$

83 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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:

  • $3 \mid n$ and $3 \mid n-1$, but this is never the case
  • $9 \mid n$ (this is where $n \equiv 0)$
  • $9 \mid n-1$ (this is where $n \equiv 1)$
1
On

The proof is like this:

$k\equiv S(k)\pmod{9}$ (well known from school) so $S(n)=S(n^2)\implies n\equiv n^2\pmod{9}\implies n(n-1)\equiv 0\pmod{9}$