For any positive integer $k$ let $f_1(k)$ denote the sum of the squares of the digits of $k$ (when written in decimal), and for $n \ge 2$ define $f_n(k)$ iteratively by $f_n(k)=f_1(f_{n-1}(k))$ .

Find $f_{2017}(2016)$ .

The answer is 42.

**
This section requires Javascript.
**

You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.

Starting from $k = 2016$ and iterating the map “sum of squares of the digits” we obtain the chain $2016 \rightarrow 41 \rightarrow 17 \rightarrow 50 \rightarrow 25 \rightarrow 29 \rightarrow 85 \rightarrow 89 \rightarrow 145 \rightarrow 42 \rightarrow 20 \rightarrow 4 \rightarrow 16 \rightarrow 37 \rightarrow 58 \rightarrow 89$ , after which the sequence repeats itself, with period $8$ .

Thus, $f_1(2016) = 41, f_2(2016) = 17$ , etc., and $f_{n+8}(2016) = f_n(2016)$ for all integers $n \ge 7$ .

Since $2017 = 8 . 251 + 9$ , it follows that follows that $f_{2017}(2016) = f_9(2016) = 42$ .