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 some 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$.

Note first that if $n \in \mathcal T$, then any integer whose digits are a permutation of the digits of $n$ is also in $\mathcal T$.

Thus the permutations of the elements of $\mathcal S$ are also in $\mathcal T$:
 * $24, 61, 73, 85, 98, 154, 415, 451, 514, 541$


 * $f \left({2}\right) = 2^2 = 4 \in \mathcal S$

and so $2 \in \mathcal T$.

Hence the above integers and their permutations:
 * $3, 9, 18, 56, 61, 65, 81$

are in $\mathcal T$.