# Squares of sum of digits of a number

I encountered the following property:

If you take a number, add up its digits, square it, take the resulting number, and repeat the process after a finite number of steps, you will get 1, 81, 169, or 256 only as the answer.

(Actually, the 169 and 256 will keep alternating.)

For all numbers I tried, it was true, but I could not prove it mathematically.

Also, the answer would be 81 if the number is divisible by 3, but again I cannot prove it.

Can anyone give me a hint as I would like to complete it myself?

• Did you know that we can check for divisibility by $9$ by adding up the digits of a number and checking that for divisibility by $9$? Do you know why that works? Can you use that knowledge to help here? Commented Oct 31, 2023 at 14:51
• If $f(n)$ is the sum of the squares of the digits of $n,$ then $$f(n)\leq 81\left(\lfloor \log_{10} n\rfloor +1\right).$$ So you will likely only need to check a finite set of values $n.$ Commented Oct 31, 2023 at 14:52
• For example, if $n>1000,$ then $f(n)<n.$ Commented Oct 31, 2023 at 14:54
• So you only need to check $n$ for $n<1000.$ But then $f(n)\leq 81\cdot 3=243,$ so you only really need to check $n\leq 243.$ Commented Oct 31, 2023 at 15:01
• For heuristics see oeis.org/A177148 Commented Oct 31, 2023 at 15:06

Let $$S(m)$$ be the digit sum of $$m$$ in the decimal system.

Let $$N:=\displaystyle\sum_{k=0}^{m}10^ka_k$$ (where $$a_k$$ are integers satisfying $$0\le a_k\le 9$$ and $$a_m\not=0$$) be the number we first take. Then, we have $$N\rightarrow (S(N))^2$$.

Here, we can say that if $$m\ge 4$$, then $$N\gt (S(N))^2=\bigg(\sum_{k=0}^{m}a_k\bigg)^2\tag1$$

A proof of $$(1)$$ is written at the end of this answer.

From $$(1)$$, we can say that, after a finite number of steps, we get a number $$M_1$$ satisfying $$M_1\le 9999$$.

Then, we get a square number $$M_2^2$$ satisfying $$M_2^2\le (9+9+9+9)^2=36^2=1296$$ since if $$m\le 9999$$, then the max of $$S(m)$$ is $$S(9999)=36$$.

Then, we get a square number $$M_3^2$$ satisfying $$M_3^2\le (9+9+9)^2=27^2=729$$ since if $$m\le 1296$$, then the max of $$S(m)$$ is $$S(999)=27$$. (proof : Suppose that there is $$m$$ satisfying $$m\le 1296, S(m)\ge 27$$ and $$m=\overline{1abc}$$. Then, we have $$a+b+c\ge 26$$. Since $$a\le 2$$, we have $$b+c\ge 24$$ which is impossible.)

Then, we get a square number $$M_4^2$$ satisfying $$M_4^2\le (6+9+9)^2=24^2=576$$ since if $$m\le 729$$, then the max of $$S(m)$$ is $$S(699)=24$$. (proof : Suppose that there is $$m$$ satisfying $$m\le 729, S(m)\ge 24$$ and $$m=\overline{7ab}$$. Then, we have $$a+b\ge 17$$. Since $$a\le 2$$, we get $$b\ge 15$$ which is impossible.)

Then, we get a square number $$M_5^2$$ satisfying $$M_5^2\le (4+9+9)^2=22^2=484$$ since if $$m\le 576$$, then the max of $$S(m)$$ is $$S(499)=22$$. (proof : Suppose that there is $$m$$ satisfying $$m\le 576,S(m)\ge 22$$ and $$m=\overline{5ab}$$. Then, we have $$a+b\ge 17$$. Since $$a\le 7$$, we have $$b\ge 10$$ which is impossible.)

Then, we get a square number $$M_6^2$$ satisfying $$M_6^2\le (3+9+9)^2=21^2=441$$ since if $$m\le 484$$, then the max of $$S(m)$$ is $$S(399)=21$$. (proof : Suppose that there is $$m$$ satisfying $$m\le 484,S(m)\ge 21$$ and $$m=\overline{4ab}$$. Then, we have $$a+b\ge 17$$. Since $$a\le 8$$, we have $$b=9$$, and so $$a=8$$ and $$m=489$$ which is impossible.)

• $$21^2\rightarrow 9^2$$

• $$20^2\rightarrow \color{red}{4^2}\rightarrow \color{blue}{7^2}\rightarrow 13^2$$

• $$19^2\rightarrow \color{purple}{10^2}\rightarrow 1^2$$

• $$18^2\rightarrow 9^2$$

• $$17^2\rightarrow 19^2$$

• $$15^2\rightarrow 9^2$$

• $$14^2\rightarrow 16^2$$

• $$12^2\rightarrow 9^2$$

• $$11^2\rightarrow \color{red}{4^2}$$

• $$8^2\rightarrow \color{purple}{10^2}$$

• $$6^2\rightarrow 9^2$$

• $$5^2\rightarrow \color{blue}{7^2}$$

• $$3^2\rightarrow 9^2$$

• $$2^2\rightarrow \color{red}{4^2}$$

Therefore, the claim follows.

In the following, let us prove that if $$m\ge 4$$, then $$N\gt (S(N))^2=\bigg(\sum_{k=0}^{m}a_k\bigg)^2\tag1$$

Proof : We have $$N=\displaystyle\sum_{k=0}^{m}10^ka_k\ge 10^m$$ and $$(9(m+1))^2\ge\bigg(\displaystyle\sum_{k=0}^{m}a_k\bigg)^2$$.

So, in order to prove $$(1)$$, it is sufficient to prove by induction on $$m$$ that $$10^m\gt (9(m+1))^2$$.

For $$m=4$$, it holds since $$10^4-(9\times 5)^2=7975>0$$.

Suppose that $$10^m\gt (9(m+1))^2$$. Then, we have \begin{align}&10^{m+1}-(9(m+2))^2 \\\\&=10\cdot 10^m-(9(m+2))^2 \\\\&\gt 10(9(m+1))^2-(9(m+2))^2 \\\\&=81(9m^2+16m+6) \\\\&\gt 0.\ \square\end{align}

• That was a really clever approach. However to make this easier for people like me to understand I would like to add a few points that might seem obvious to some. First: The reason why we stopped at $M_6$ only was because before that our procedure was decreasing the minimum value of the termination point of the sequence by atleast 100 which also decreased the max value of the sum. But after 484 we got 441 and the upper bound stayed the same Commented Apr 8 at 13:48
• Second for 5 or more digits $N\gt (S(N))^2=\bigg(\sum_{k=0}^{m}a_k\bigg)^2\tag1$ implies that implies that $N\lt (S(N))^2=\bigg(\sum_{k=0}^{m}a_k\bigg)^2\tag1$ for 4 digits or less and so our number definitely decreases and after some time it becomes less than 10000 and this is the only upper bound we can get from this condition. Commented Apr 8 at 13:54