If $(f(x))^n$ is a polynomial for all $n\ge 2$, $n\in\mathbb Z$, then is $f(x)$ a polynomial? 
$f:\mathbb R\to \mathbb R$ is such that $(f(x))^n$ is a polynomial for all $n\ge 2$, $n\in\mathbb Z$. Is $f(x)$ necessarily a polynomial?

My attempt: The condition is equivalent to $(f(x))^p$ being a polynomial for all primes $p$. Also, clearly $f(x)$ is a ratio of two polynomials.
 A: Hint $\ f^2,f^3\in \Bbb R[x]\,\Rightarrow\, f = f^3/f^2 \in \Bbb R(x)\,$ so $\,f^2 \in \Bbb R[x]\,\,\Rightarrow\,f \in \Bbb R[x]\, $ by the Rational Root Test (which works over any UFD, with same proof as in $\,\Bbb Z)$ 
More explicitly if $\,f^2 = p\in \Bbb R[x]\,$ then $\,f\,$ is a root of the monic $\,y^2 - p\in S[y]$ over the UFD $\,S = \Bbb R[x],\,$ so by RRT the reduced denominator of $\,f\,$ divides the lead coef $= 1\,$ of $\ y^2 - p.\ $  Hence the denominator of $\,f\,$ is a unit, i.e. the polynomial fraction $\,f\,$ is "integral", i.e. $\,f\in \Bbb R[x].$
Remark $\ $ This is a polynomial analog of the classical irrationality proofs for square-roots of numbers. Most of the proofs for numbers will also work here (e.g. comparing the parity of exponents in the (unique) prime factorizations on both sides).
A: If $f=0$ you're done, so suppose otherwise.
Write:
$$f(x)=\frac{f^3(x)}{f^2(x)}=\frac{p(x)}{q(x)},$$
for polynomials $p,q$.
From which it follows that
$$q(x)=f^2(x)=\frac{p^2(x)}{q^2(x)}.$$
Now suppose that $p(x)$ has a root $r$ and $q(r)\neq 0$ 
Rearranging this gives $q^3(x)=p^2(x)$ locally around $r$. This is clearly impossible since $q,p$ are polynomials, hence $q(x)$ and $p(x)$ must have the same roots (repeat the argument for $q(x)$ having a root $r$ but $p(x)$ not). You can show that $p(x)$ must have degree larger than $q(x)$ from which it follows that $f(x)$ is a polynomial. 
A: Yes. More generally:

If $D$ is a UFD, $R$ a ring extension of $D$, $x\in R$ such that $x^n\in D$ for all $n>1$, then $x\in D$.

Proof. $(x^2)^2\mid(x^3)^2\overset{UFD}\implies x^2\mid x^3\implies x\in D$.
Yours is the case $D=\mathbb R[x]$, $R=\mathbb R^{\mathbb R}$.
A: I'll answer my own question based on the comment.
If $(f(x))^2\equiv 0$, then $f(x)\equiv 0$ is also a polynomial. Let $(f(x))^2\not\equiv 0$.
$f(x)=\frac{(f(x))^3}{(f(x))^2}=\frac{p(x)}{q(x)}$ is a ratio of two polynomials $p(x)$, $q(x)$  with real coefficients.
$f(x)^2=r(x)$ is another polynomial with real coefficients.
Therefore $(p(x))^2=(q(x))^2r(x)$, so $(q(x))^2$ divides $(p(x))^2$, i.e. $q(x)$ divides $p(x)$, so $f(x)=\frac{p(x)}{q(x)}$ is a polynomial.
It was enough to claim that $(f(x))^2$, $(f(x))^3$ are polynomials to conclude $f(x)$ is a polynomial. More generally, $(f(x))^m$, $(f(x))^{km+1}$ could be polynomials for some $k,m\in\mathbb Z^+$ to conclude $f(x)$ is also a polynomial.
As barto claims in a comment, by Bézout's Lemma it's enough to know $(f(x))^a$, $(f(x))^b$ are polynomials, where $a,b\in\mathbb Z^+$ and $\gcd(a,b)=1$, to conclude that $f(x)$ is a polynomial.
