Problem: Let $K$ be the set of positive integers not containing the decimal digit $7$.
Determine all polynomials $f(x)$ with nonnegative coefficients
such that $f(x) \in K$ for all $x \in K$.

Solution: The answer is only the obvious ones:
$f(x) = 10^e x$, $f(x) = k$,
and $f(x) = 10^e x + k$, for any choice of $k \in K$
and $e > \log_{10} k$ (with $e \ge 0$).

Now assume $f$ satisfies $f(K) \subseteq K$;
such polynomials will be called \emph{stable}.
We first prove the following claim
which reduces the problem to the study of monomials.
\begin{lemma*}
  [Reduction to monomials]
  If $f(x) = a_0 + a_1 x + a_2 x^2 + \dots$ is stable,
  then each monomial $a_0$, $a_1 x$, $a_2 x^2$, \dots is stable.
\end{lemma*}
\begin{proof}
  For any $x \in K$, plug in $f(10^e x)$ for large enough $e$:
  the decimal representation of $f$ will contain
  $a_0$, $a_1 x$, $a_2 x^2$ with some zeros padded in between.
\end{proof}

Let's tackle the linear case next.
Here is an ugly but economical proof.
\begin{claim*}
  [Linear classification]
  If $f(x) = cx$ is stable, then $c = 10^e$
  for some nonnegative integer $e$.
\end{claim*}
\begin{proof}
  We will show when $c \neq 10^e$ then we can find $x \in K$
  such that $cx$ starts with the digit $7$.
  This can actually be done with the following explicit cases
  in terms of how $c$ starts in decimal notation:
  \begin{itemize}
    \ii For $9 \cdot 10^e \le c < 10 \cdot 10^e$, pick $x = 8$.
    \ii For $8 \cdot 10^e \le c < 9 \cdot 10^e$, pick $x = 88$.
    \ii For $7 \cdot 10^e \le c < 8 \cdot 10^e$, pick $x = 1$.
    \ii For $4.4 \cdot 10^e \le c < 7 \cdot 10^e$, pick $11 \le x \le 16$.
    \ii For $2.7 \cdot 10^e \le c < 4.4 \cdot 10^e$, pick $18 \le x \le 26$.
    \ii For $2 \cdot 10^e \le c < 2.7 \cdot 10^e$, pick $28 \le x \le 36$.
    \ii For $1.6 \cdot 10^e \le c < 2 \cdot 10^e$, pick $38 \le x \le 46$.
    \ii For $1.3 \cdot 10^e \le c < 1.6 \cdot 10^e$, pick $48 \le x \le 56$.
    \ii For $1.1 \cdot 10^e \le c < 1.3 \cdot 10^e$, pick $58 \le x \le 66$.
    \ii For $1 \cdot 10^e \le c < 1.1 \cdot 10^e$, pick $x = 699\dots9$
    for suitably many $9$'s. \qedhere
  \end{itemize}
\end{proof}

The hardest part of the problem is the case where $\deg f > 1$.
We claim that no solutions exist then:
\begin{claim*}
  [Higher-degree classification]
  No monomial of the form $f(x) = cx^d$ is stable
  for any $d > 1$.
\end{claim*}
\begin{proof}
  Note that $f(10x+3)$ is stable too.
  Thus
  \[ f(10x+3) = 3^d + 10d \cdot 3^{d-1} x
    + 100 \binom d2 \cdot 3^{d-1} x^2 + \dots \]
  is stable.
  By applying the lemma the linear monomial
  $10d \cdot 3^{d-1} x$ is stable,
  so $10d \cdot 3^{d-1}$ is a power of $10$,
  which can only happen if $d = 1$.
\end{proof}

Thus the only nonconstant stable polynomials with nonnegative coefficients
must be of the form $f(x) = 10^e x + k$ for $e \ge 0$.
It is straightforward to show we then need $k < 10^e$
and this finishes the proof.

\begin{remark*}
  The official solution replaces the proof for $f(x) = cx$ with Kronecker density.
  Here is how it goes.

  From $f(1) = c \in K$, we get $f(c) = c^2 \in K$,
  et cetera and hence $c^n \in K$.
  However, I claim that when $c$ is not a power of $10$,
  some power of $c$ starts with \emph{any} specified prefix.
  For example, there should be an integer $n$
  such that $c^n$ starts with the digits $98765$.
  And this is obviously a contradiction to $c^n \in K$.

  To see why, note this is equivalent to requiring that
  \[ \log_{10}(9.8765) \le \{ n \log_{10} c \} < \log_{10}(9.8766) \]
  where $\{x\}$ is the fractional part of $x$.
  However, when $c$ is not a power of $10$, the number $\log_{10}(c)$ is irrational.
  And Kronecker density theorem asserts that whenever $\alpha$ is irrational,
  the fractional parts $\{ n \alpha \}$ for $n \ge 0$
  are actually equally distributed across the entire open interval $(0,1)$.
  In particular, there are $n$ for which the fractional part lie in any
  interval of positive length.
\end{remark*}