A nice integer is of the form 111...11. Find the non-constant $P \in \mathbb{R}[X]$ such that if $n \in \mathbb{N}$ is nice, then $P(n)$ is nice.

Hint: Study the behavior at infinity and use the rigidity of polynomials.
Let's consider such a polynomial $P$, denote $d$ its degree and $a_{d}$ its leading coefficient. The nice integers are exactly of the form $\frac{10^{n}-1}{9}$ with $n \geq 1$. For $n \in \mathbb{N}^{*}$, we then denote $P\left(\frac{10^{n}-1}{9}\right)=$ $\frac{10^{k n}-1}{9}$.

Then as $n$ tends to infinity,

$$
\frac{a_{d}\left(10^{n}-1\right)^{d} \cdot 9}{9^{d} \cdot\left(10^{k_{n}}-1\right)}
$$

tends to 1.

Therefore, $10^{n d-k_{n}}$ converges. (by factoring out the powers of 10 that tend to infinity). Thus, $\left(n d-k_{n}\right)$ converges, and since it is a sequence of integers, there exists $a \in \mathbb{Z}$ such that for sufficiently large $n$, $k_{n}=n d+a$.

Therefore, for some value of $n>0$, we have

$$
P\left(\frac{10^{n}-1}{9}\right)=\frac{10^{n d+a}-1}{9}=\frac{10^{a}}{9} \cdot\left(9 \cdot \frac{10^{n}-1}{9}+1\right)^{d}-\frac{1}{9}
$$

Since the set of $\frac{10^{n}-1}{9}$ for sufficiently large $n$ is infinite, $P(X)=\frac{10^{a}}{9} \cdot(9 X+1)^{d}-\frac{1}{9}$.

We can verify that these polynomials are indeed solutions for $d \geq 1$ and $a \in \mathbb{Z}$.