4. Find all polynomials $P(x)$ with real coefficients such that
$$
P(a) \in \mathbb{Z} \quad \text { implies that } \quad a \in \mathbb{Z} \text {. }
$$
4. Let $P(x)=a_{n} x^{n}+\cdots+a_{1} x+a_{0}$. Define $Q(x)=P(x+1)-P(x)$. Then $Q(x)$ is of degree $n-1$. We'll prove by contradiction that $|Q(x)| \leq 3$ for all $x$. This will imply that $n \leq 1$. Assume that $|Q(a)|>3$ for some $a \in \mathbb{R}$. Then $|P(a+1)-P(a)|>3$. Thus there are 3 integers between $P(a)$ and $P(a+1)$. Hence there exists three values of $x \in[a, a+1]$ such that $P(x)$ is an integer. Thus there are three integers in $[a, a+1]$, a contradiction. There are two cases:
Case (i) $n=0$. Here we have $P(x)=c$ where $c \notin \mathbb{Z}$.
Case (ii) $n=1$. Here $P(x)=s x+t$. There are two integers $m, n$ such that $P(m)=s m+t=0$ and $P(n)=s n+t=1$. Thus $s(n-m)=1$ implying that $1 / s \in \mathbb{Z}$ and $s m+t=0$ implying that $t / s \in \mathbb{Z}$. Letting $1 / s=p$ and $t / s=q, P(x)=\frac{x}{p}+\frac{q}{p}$ where $p, q \in \mathbb{Z}$ and $p \neq 0$.