Problem

Source: 2007 Cuba MO 2.8

Tags: number theory, sum of digits, Periodic sequence, periodic



For each positive integer $n$, let $S(n)$ be the sum of the digits of $n^2 +1$. A sequence $\{a_n\}$ is defined, with $a_0$ an arbitrary positive integer and $a_{n+1} = S(a_n)$. Prove that the sequence $\{a_n\}$ is eventually periodic with period three.