Sequence of Sum of Squares of Digits

Theorem
For a positive integer $n$, let $\map f n$ be the integer created by adding the squares of digits of $n$.

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

Let $\sequence {S_m}_{n \mathop \in \Z_{>0} }$ be the sequence defined as follows:


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

\map f {n_{k - 1} } & : n > 1 \end{cases}$

Then eventually either $\sequence {S_m}$ 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$, $\map f m < m$.

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

Starting from the bottom, we have that:


 * $\map f 1 = 1^2 = 1$

and so $\sequence {S_1} = 1, 1, 1, \ldots$

We note the sequence:

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

It remains to test the rest.

Let $\TT$ be the set of integers $m$ for which $S_m$ ends up either in $\SS$ or $1$.

Then the elements of $\SS$ are all in $\TT$, as is $1$.

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

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

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

to denote:
 * $\map f a = b, \map f b = c$

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

So: