# Squares of sum of digits of numbers part 3

This is the third part of my first post about properties of sum of squares of a number. Anyone who is new may refer to the link below.

Squares of sum of digits of a number

Here is a quick summary:

Take a number then add up it digits and square the result. Repeat the process to the number obtained and keep doing so. I the end we will get either $$1,81,169,256$$. This was proved in the first post.

Now suppose we do this to a number until we get $$1,81,169,256$$. The moment we get anyone number out of the $$4$$ we stop the sequence. What is the probability that the sequence ends in any one of $$1,81,169,256$$.

• How are you choosing the starting number? You can't choose a natural number uniformly at random. You could do so through a distribution e.g. geometric.
– A.M.
Commented Apr 11 at 15:25
• Please edit your post to make it self-contained. I can't tell what your question is. Don't force us to click on links to understand what you are asking. We are a question-and-answer site, so we require you to articulate a specific question. Normally a question should end with "?"
– D.W.
Commented Apr 15 at 7:05
• What are your thoughts? What is the motivation for why others might care about this question or the context in which it arose?
– D.W.
Commented Apr 15 at 7:05
• @D.W. here is the full story. Disclaimer: it may be boring..... In 2023 I qualified for the second stage of international mathematical olympiad in my country and there was a question in the exam to find all distinct numbers m and n such that square of sum of digits of m is equal to n and square of sum of digits of n equals m. The question in the link was a lemma I used during the proof but failed to prove it in exam and so got 0 for that question. But I tried to find answers on MSE and it was one of my popular posts. I was just thinking about other aspects in the problem that led to this. Commented Apr 15 at 8:18
• The above was my motivation and why I care. As for others I don't think they would have any other reason to care except for the bounty or the fact that this is a wonderful amalgamation of probability and number theory. Commented Apr 15 at 8:19

Here's a partial answer, under the assumption that you want to take a uniform random starting number from $$\{1, \dots, N\}$$ and then look at the limiting behavior as $$N \to \infty$$.

Let $$f(n)$$ denote the first number from $$\{1, 81, 169, 256\}$$ that we land on starting at $$n$$. If $$s(n)$$ is the sum of the digits of $$n$$, then $$s(n) \equiv n \pmod 9$$. This is well-known and easy to show. Then $$s(n)^2 \equiv n^2 \pmod 9$$.

Let's look at numbers and their squares modulo $$9$$. I'll split them into three classes: $$A = \{0, 3, 6\}$$, $$B = \{1, 8\}$$, and $$C = \{2, 4, 5, 7\}$$. Every number in each class squares to another number in the same class. Therefore, if our starting number $$n$$ is in a certain class, then $$f(n)$$ is in the same class. If $$n \in A \pmod 3$$ then $$f(n) = 81$$, and if $$n \in B \pmod 9$$ then $$f(n) = 1$$. As $$N \to \infty$$, the probability that a uniform random $$n$$ falls into class $$A$$ approaches $$1 / 3$$. And similarly for class $$B$$ we get $$2 / 9$$.

Now, how is the remaining $$4 / 9$$ probability split between $$169$$ and $$256$$? This I can't answer. All numbers in class $$C$$ alternate between $$4$$ and $$7$$ modulo $$9$$, so I would have guessed that about half would land on $$169 \equiv 7 \pmod 9$$ and the other half on $$256 \equiv 4 \pmod 9$$. However, running a computer simulation seems to indicate that very large numbers are about twice as likely (or more) to land on $$169$$ than $$256$$.

I have performed a computer simulation that calculates the exact probabilities of ending at $$\{0, 1, 81, 169, 256\}$$ from a starting number in $$\{0, 1, \dots, 10^d\}$$ for $$1 \leq d < 5000$$. Note that ending at $$0$$ is only possible if the starting number equals $$0$$, so this probability will vanish as $$d \to \infty$$.

I have plotted the result, which can be seen below. In the plot, the value of $$d$$ is listed on the x-axis and the probability of ending at each of $$\{0, 1, 81, 169, 256\}$$ is listed on the y-axis.

Note that this answer does not answer the question, it is merely an interesting result, which did not fit in a comment.

Update: I improved my algorithm, which can now approximate (to unknown accuracy) the probabilities of ending at $$\{0, 1, 81, 169, 256\}$$ from a starting number in $$\{0, 1, \dots, 10^{2^p}\}$$ for $$1 \leq p \leq 26$$.

Listing the probability of ending at $$169$$ and $$256$$, respectively, for some $$p$$'s we get:

20: [0.3229072415185169, 0.1215372029259365]
21: [0.3525997163737325, 0.0918447280707314]
22: [0.3565506315236761, 0.0878938129207874]
23: [0.3553829797083236, 0.0890614647361787]
24: [0.3092395404207834, 0.1352049040237175]
25: [0.3217452008711443, 0.1226992435733908]
26: [0.3294311770014319, 0.1150132674431534]


which give lower probabilities of ending at $$256$$ than the values I computed before. This may signify that as $$p \to \infty$$ we may have $$0$$ probability of ending at $$256$$, but that is just a guess.

• This does give a verification of the result of user crb233 but does the probability of 169 or 256 approach any number? Commented Apr 16 at 13:12
• @AarushSaharan, I don't know what number it approaches. I updated my answer, but I did not find an answer to that question (yet). Commented Apr 17 at 0:36
• Maybe the probability just keeps oscillating like in your graph. Can we predict is behavior? Commented Apr 17 at 1:24
• Does anyone notice that probability of 169 and 256 are reflections of each other in tthe graph. Why is this true? Commented Apr 20 at 0:44
• @AarushSaharan, logically the sum of all the probabilities equals 1. The probability of ending at 0 quickly converges to 0. By crb233's answer we known that the probability of landing at 169 plus the probability of landing at 256 equals $4/9$. Both graphs are thus reflections around $2/9$, which is coincidentally the same as the probability of landing on 1. Commented Apr 20 at 15:55