TITLE: Repeated sum of square of digits always arrives at $1$ or $89$
QUESTION [6 upvotes]: I found an astonishing result in a problem today here !
A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.
For example,
$44 \to 32 \to 13 \to 10 \to 1 \to 1$
$85 \to 89 \to 145 \to 42 \to 20 \to 4 \to 16 \to 37 \to 58 \to 89$ 
Therefore any chain that arrives at $1$ or $89$ will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at $1$ or $89$.
Why is this true?

REPLY [2 votes]: Let us observe that, for any function $g: \mathbb{N} \to \mathbb{N}$,
if we apply $g$ repeatedly to $n$ we will eventually arrive at a positive integer $k$ such that $g(k) \ge k$.
Why? Because if not, then $n > g(n) > g(g(n)) > g(g(g(n))) > \cdots$, but this can only go on finitely long since $g$ lies in the positive integers.
Therefore the same is true of $f$, and it suffices to consider only values of $\boldsymbol{n}$ for which $\boldsymbol{f(n) \ge n}$.
Let us search for all such values.

First, $n$ must have $3$ or less digits.
Others have already proven this, but let $k$ be the number of digits of $n$.
Then the sum of the squares of the digits (i.e. $f(n)$) is at most $81k$.
On the other hand, $n$ is at least $10^{k-1}$.
So $n$ is very large but $f(n)$ is much smaller. Formally, we can say that if $\boldsymbol{k \ge 4}$ then $10^{k-1} > 81k$ so
$$
n \ge 10^{k-1} > 81k \ge f(n).
$$
Therefore, $f(n) < n$ for all $n$ with four or more digits, i.e. for all $n \ge 1000$.
So we can assume $1 \le n \le 999$.
Now let's assume $n$ has three digits: $n = 100a + 10b + c$, where $a \ge 1$. We need $a^2 + b^2 + c^2 \ge 100a$, so
$$
100a \le 3 \cdot 9^2 = 243,
$$
so $a = 1$ or $a = 2$. But now $100a \le a^2 + b^2 + c^2 \le 4 + 2 \cdot 9^2 = 166$, so $a = 1$. So we need $1 + b^2 + c^2 \ge 100 + 10b + c$, or in other words $b^2 + c^2 - 10b - c \ge 99$. Now $b^2 - 10b < 0$, so the best we can do is $9^2 - 9 < 99$, so this is impossible.
So we are left with considering $n = 10a + b$. Now we are simply solving the inequality $a^2 + b^2 \ge 10a + b$, for $0 \le a, b \le 9$. The inequality can be rewritten
$$
b(b-1) \ge a(10 - a).
$$
This leads to the following solutions for $n$:
\begin{align*}
a = 0
&\implies n = 1, 2, 3, 4, 5, 6, 7, 8, 9 \\
a = 1
&\implies n = 14, 15, 16, 17, 18, 19 \\
a = 2
&\implies n = 25, 26, 27, 28, 29 \\
a = 3
&\implies n = 36, 37, 38, 39 \\
a = 4
&\implies n = 46, 47, 48, 49 \\
a = 5
&\implies n = 56, 57, 58, 59 \\
a = 6
&\implies n = 66, 67, 68, 69 \\
a = 7
&\implies n = 76, 77, 78, 79 \\
a = 8
&\implies n = 85, 86, 87, 88, 89 \\
a = 9
&\implies n = 94, 95, 96, 97, 98, 99.
\end{align*}
So we need to show that applying $f$ repeatedly to any of the above will get $1$ or $89$.
This can be done quite simply, by repeatedly applying $f$ to each individual element; for example,
$$
2 \to 4 \to 16 \to 37 \to 58 \to 89
$$
which knocks out $6$ of the above possibilities.
And
$$
3 \to 9 \to (81) \to 17 \to (50) \to 25 \to 29 \to 85 \to 89,
$$
knocking out several more (I put numbers $n$ such that $f(n) < n$ in parentheses, since we don't care about them.)
We can proceed in this manner, just checking what happens for a specific value, until all of the numbers above are accounted for, and then we have proven that we will eventually arrive at $1$ or $89$.

As others have pointed out, while $f(1) = 1$, $89$ is not so special -- we don't have $f(89) = 89$, but instead it is part of a cycle of $8$ numbers.