TITLE: $m$-fold composite $p^{(m)}(x) \in \mathbb{Z}[x]$ implies $p(x) \in \mathbb{Z}[x]$
QUESTION [27 upvotes]: Let $p(x)$ be a polynomial, $p(x) \in \mathbb{Q}[x]$, and $p^{(m+1)}(x)=p(p^{(m)}(x))$ for any positive integer $m$.
If $p^{(2)}(x) \in \mathbb{Z}[x]$ it's not possible to say that $p(x) \in \mathbb{Z}[x]$.
Is it possible to conclude that $p(x) \in \mathbb{Z}[x]$ if $p^{(2)}(x) \in \mathbb{Z}[x]$ and $p^{(3)}(x) \in \mathbb{Z}[x]$?
More general, suppose there exist positive integers $k_1 <k_2$, such that $p^{(k_1)}(x) \in \mathbb{Z}[x]$ and $p^{(k_2)}(x) \in \mathbb{Z}[x]$. Does it follow that $p(x) \in \mathbb{Z}[x]$?

REPLY [5 votes]: $\def\QQ{\mathbb Q}\def\ZZ{\mathbb Z}$Here is a more elementary proof of the key Lemma in the very nice @Dávid E. Speyer’s answer, pasted here for convenience.

Lemma: Let $f$ be a polynomial in $\QQ_p[x]$ which is not in $\ZZ_p[x]$, and suppose that the constant term $f_0$ is in $\ZZ_p$. Then $f^{(2)}$ is not in $\ZZ_p[x]$.

Set $v_i=v(f_i)$; choose an index $t$ minimizing $v_t(<0)$; if there are several minimal values, take the maximal $t$. By the assumptions, we have $t>0$. Performing such choice for the polynomial $F_r(x)=f_rf(x)^r$, we get the index $rt$ with the valuation $v_r+rv_t$ (one way to see it is, again, via Newton polygons, but these inequalities can be easily written down explicitly).
Choose now an index $s$ minimizing $M=v_s+sv_t$, taking again the maximal index given a multiple choice. We have $M\leq v_t+tv_t<0$; therefore, $s>0$, since $v_0\geq0$. Then $M$ is the minimal valuation of a coefficient in all the $F_i$; moreover, such valuation appears in the coefficient of $x^{st}$ exactly once —that is, in $F_s(x)$. Therefore, in $f^{(2)}(x)$ the coefficient of $x^{st}$ also has  valuation $M<0$.