Lisa writes a positive integer in the decimal system on the board and now does the following in each move:

The last digit of the number on the board is erased, and then the four times the erased digit is added to the now shorter remaining number (or to 0 if the number was a single digit). The number on the board is then replaced by the result of this calculation.

Lisa repeats this until she gets a number that has already appeared on the board for the first time.

(a) Show that the sequence of moves always ends.

(b) What number is on the board at the end if Lisa starts with the number $53^{2022}-1$?

Example: If Lisa starts with the number 2022, she gets $202+4 \cdot 2=210$ in the first move, and overall the sequence is

$$
2022 \mapsto 210 \mapsto 21 \mapsto 6 \mapsto 24 \mapsto 18 \mapsto 33 \mapsto 15 \mapsto 21
$$

Since Lisa gets 21 for the second time, the sequence of moves ends.

(Stephan Pfannerer)
Let $f$ be the mapping that results from the calculation rule. If we write the positive integer $x$ uniquely as $10a + b$ with $a, b \in \mathbb{Z}_{\geq 0}$ and $0 \leq b \leq 9$, we get $f(x) = f(10a + b) = a + 4b$. Furthermore, let $\left(x_{i}\right)_{i \geq 0}$ be the sequence of numbers that Lisa obtains when she starts with the positive integer $x_{0}$. This sequence is given by the recursion $x_{i+1} = f\left(x_{i}\right)$.

(a) Directly from the definition, we see that $x_{i} \in \mathbb{Z}_{>0}$ for all $i \geq 0$ (and thus the process is well-defined).

We first show that for $x_{i} \geq 40$, the subsequent term in the sequence is strictly smaller, i.e., $x_{i} > x_{i+1}$. Let $x_{i} = 10a + b$ as above. We get from $10a + b = x_{i} > x_{i+1} = a + 4b$ by rearranging the equivalent inequality $9a > 3b$. Since by assumption $x_{i} \geq 40$, $a > 3$ must hold, and thus the inequality is valid.

Furthermore, it is easy to show that for $x_{i} \leq 39$, $x_{i+1} \leq 39$ also holds. For $x_{i} = 10a + b \leq 39$, $a \leq 3$ and $b \leq 9$ must hold. Therefore, $x_{i+1} = f\left(x_{i}\right) = a + 4b \leq 3 + 4 \cdot 9 = 39$.

Thus, there exists an integer $N \geq 0$ such that $x_{i} \in \{1, 2, \ldots, 39\}$ for all $i \geq N$. Since there are only finitely many different values, there exist $i \neq j$ with $x_{i} = x_{j}$.

(b) The answer is 39. We first observe that $f(x) \equiv 4 \cdot x \pmod{39}$. Let $x = 10a + b$ as above, then we have:

$$
f(x) = a + 4b \equiv 40a + 4b = 4 \cdot (10a + b) = 4x \quad (\bmod 39).
$$

We now examine our starting value modulo 39. We have

$$
53^{2022} - 1 \equiv 1^{2022} - 1 \equiv 0 \quad (\bmod 13)
$$

and similarly

$$
53^{2022} - 1 \equiv (-1)^{2022} - 1 \equiv 0 \quad (\bmod 3)
$$

and thus $39 \mid 53^{2022} - 1 = x_{0}$. By induction, we get with the above observation $39 \mid x_{i}$ for all $i \geq 0$.

Let $N$ be the first index in the sequence with $0 < x_{N} < 40$. Since $39 \mid x_{N}$, $x_{N} = 39$ must hold. Because for all $i < N$ the sequence $x_{i}$ is strictly decreasing and $f(39) = 39$, 39 is the number that appears for the first time twice on the board. 

(Michael Drmota)