Determine all digits $z$ such that for every integer $k \geq 1$ there exists an integer $n \geq 1$ with the property that the decimal representation of $n^{9}$ ends with at least $k$ digits $z$.

(Walther Janous)
Answer: The sought digits $z$ are $z \in\{0,1,3,7,9\}$.

We set $z_{k}:=(\underbrace{z \ldots z}_{k})_{10}$ for $k \geq 1$ and note that the problem statement is equivalent to solving the congruence

$$
n^{9} \equiv z_{k} \quad\left(\bmod 10^{k}\right)
$$

for $k \geq 1$.

For $z=0$, set for example $n=10^{k}$. From now on, consider only $z \in\{1, \ldots, 9\}$.

We first consider the case where $\operatorname{gcd}(z, 10) \neq 1$. Then there is a prime $p \in\{2,5\}$ with $p \mid z$. For $k=4$, (4) yields

$$
n^{9} \equiv z_{4}=z \cdot 1111 \quad\left(\bmod p^{4}\right)
$$

(since this congruence must hold modulo $10^{4}$, and hence also modulo $2^{4}$ and modulo $5^{4}$).

The right-hand side is divisible by $p$, so the left-hand side $n^{9}$ is also divisible by $p$, and thus $n$ is divisible by $p$, so $n^{9}$ is even divisible by $p^{9}$, and thus congruent to 0 modulo $p^{4}$, and therefore the right-hand side $z \cdot 1111$ is also divisible by $p^{4}$, and hence, due to $\operatorname{gcd}(1111,10)=1$, $p^{4} \mid z$. This is not possible in the decimal system because $p^{4}>10>z$. Therefore, there is no solution here.

We now consider the remaining cases $z \in\{1,3,7,9\}$. Let $r$ be the inverse residue of 9 modulo $\varphi\left(10^{k}\right)$, which exists because $\operatorname{gcd}\left(9, \varphi\left(10^{k}\right)\right)=\operatorname{gcd}\left(9,4 \cdot 10^{k-1}\right)=1$. We claim that $n:=z_{k}^{r}$ is a solution to (4). Since $\operatorname{gcd}\left(z_{k}, 10^{k}\right)=1$ and $9 r \equiv 1\left(\bmod \varphi\left(10^{k}\right)\right)$, we can easily show this with Euler-Fermat:

$$
n^{9}=\left(z_{k}^{r}\right)^{9}=z_{k}^{9 r} \equiv z_{k} \quad\left(\bmod 10^{k}\right)
$$

Note: Generally, for all integers $\ell>0, m \geq 1$ and $b$ with $\operatorname{gcd}(b, m)=1$ and $\operatorname{gcd}(\ell, \varphi(m))=1$, the congruence $n^{\ell} \equiv b(\bmod m)$ has a unique solution $n$ modulo $m$, namely $n \equiv b^{r}(\bmod m)$, where $r$ is the inverse residue of $\ell$ modulo $\varphi(m)$. The proof follows the same reasoning as above.

(Clemens Heuberger)