5.1. Let $S(n)$ be the sum of the digits in the decimal representation of the number $n$. Find $S\left(S\left(S\left(S\left(2017^{2017}\right)\right)\right)\right)$. Answer. 1.
Solution. Since $2017^{2017}<10000^{2017}$, the number of digits in the representation of $2017^{2017}$ does not exceed $4 \cdot 2017=$ 8068, and their sum $S\left(2017^{2017}\right)$ does not exceed $9 \cdot 8068=72612$. Then we sequentially obtain $S\left(S\left(2017^{2017}\right)\right) \leqslant 6+9 \cdot 4=42, S\left(S\left(S\left(2017^{2017}\right)\right)\right) \leqslant 3+9=12, S\left(S\left(S\left(S\left(2017^{2017}\right)\right)\right)\right) \leqslant 9$. Note also that the sum of the digits of a number gives the same remainder when divided by 9 as the number itself. Since 2016 is divisible by 9, the number $2017^{2017}=(2016+1)^{2017}$ gives a remainder of 1 when divided by 9. Therefore, $\left.S\left(S\left(S\left(2017^{2017}\right)\right)\right)\right)=1$.