Sum of digits of repunits
A nice problem!
Hints:
- Let $n=9q+r$ with $0\le r <9$. Show that the claimed formula gives $$ D_n=81q+r^2 $$ for the sum of digits $D_n$ of $S_n^2$.
- Therefore it suffices to check the formula for $n=1,2,\ldots,9$, and to show that for all $n$ we have the recurrence relation $$ D_{n+9}=D_n+81. $$
- For $n\le9$ verify the formula using the grade school multiplication. Observe that there will be no carry for these small values of $n$.
- Verify the identity $$ S_{n+9}^2=10^9S_n^2+\frac{10^{2n+18}-10^{2n+9}}{81}-\frac{10^9-1}{81}. $$ Here the factor $10^9$ has a predictable effect on the sum of digits, and the remaining task is to check that the two additional terms give the desired contribution. There is some work to be done there, but not an awful lot, if you notice that $$ \frac{10^9-1}{81}=12345679. $$