Suppose $f(x)$ is a function from $\mathbb{R} \rightarrow \mathbb{R}$ such that $f(f(x)) = f(x)^{2013}$. Show that there are infinitely many such functions, of which exactly four are polynomials.
I found a solution here. It goes as following (only the part relevant to this post):
If $f$ is a polynomial, then either $f$ is constant or $f$ is non-constant. In the first case, say $f(x) = c$, we get $c = c^{2013}$, so $c \in \{-1, 0, 1\}$. In the second case, the range of $f$ contains infinitely many values since $f$ is continuous, so by the identity theorem, $f(x) = x^{2013}$ is forced. Thus there are only four polynomials $f$ that work -- three constant polynomials and $f(x) = x^{2013}$.
My doubt is how exactly did they conclude $f(x) = x^{2013}$? How does the range of $f$ having infinitely many values force $f$ to be $x^{2013}$?