Sequence of Sum of Squares of Digits

Theorem
For a positive integer $n$, let $f \left({n}\right)$ be the integer created by adding the squares of digits of $n$.

Let $m \in \Z_{>0}$ be expressed in decimal notation.

Let $\left\langle{S_m}\right\rangle_{n \mathop \in \Z_{>0} }$ be the sequence defined as follows:


 * $n_k = \begin{cases} m & : n = 1 \\

f \left({n_{k - 1} }\right) & : n > 1\end{cases}$

Then eventually either $\left\langle{S_m}\right\rangle$ sticks at $1$, or goes into the cycle:
 * $\ldots, 4, 16, 37, 58, 89, 145, 42, 20, 4, \ldots$

Proof
First note that:
 * $1^2 + 9^2 + 9^2 = 163$
 * $9^2 + 9^2 + 9^2 = 243$

and it can be seen that for a positive integer $m$ larger than $199$, $f \left({m}\right) < m$.

Thus it is necessary to investigate numbers only up as far as that.

Starting from the bottom, we have that:


 * $f \left({1}\right) = 1^2 = 1$

and so $\left\langle{S_1}\right\rangle = 1, 1, 1, \ldots$

We note the sequence:

Hence any $m$ in the set $\left\{ {4, 16, 20, 37, 42, 58, 89, 145}\right\}$ stays within that sequence, which we will refer to as $\mathcal S$.

It remains to test the rest.

Let $\mathcal T$ be the set of integers $m$ for which $S_m$ ends up either in $\mathcal S$ or $1$.

Thus the elements of $\mathcal S$ are all in $\mathcal T$, as is $1$.

If $m \in \mathcal T$, then any integer $m'$ whose non-zero digits are the same as those of $m$ is also in $\mathcal T$.

Thus:
 * $2, 10, 24, 40, 61, 73, 85, 98, 100, 106 \in \mathcal T$

We use the notation:
 * $a \to b \to c$

to denote:
 * $f \left({a}\right) = b, f \left({b}\right) = c$

and work progressively through $\Z_{>0}$.

So: