4. On the board, there is a positive integer N written in decimal notation. If it is not a single-digit number, we erase its last digit c and the number $m$ that remains on the board is replaced by the number $|m-3c|$. (For example, if the number on the board was $N=1204$, after the modification, it will be $120 - 3 \cdot 4 = 108$.) Find all natural numbers N from which, by repeatedly applying the described modification, we eventually get the number 0.

(Peter Novotný)
Solution. First, we determine for which numbers $N$ we get zero right away. Apparently, $|m-3c| = 0$ precisely when $m=3c$ or $N=10m+c=31c$. All multiples of $N=31c$ for $c \in \{1,2, \ldots, 9\}$ therefore satisfy the problem.

We will prove that the problem is satisfied by exactly all natural multiples of the number 31. Since $c = N-10m$, we have $m-3c=31m-3N$, so the described operation preserves divisibility by 31. It is therefore sufficient to show that from any multiple $N=31k$, where $k \geq 10$, we always get a smaller multiple of the number 31 by the described modification. For such an $N$, however, $m \geq 31, m-3c > 0$, so $|m-3c|=31m-3N < 4N-3N=N$. This means that after a finite number of steps, we will get one of the nine smallest multiples of the number 31 by the described modification, and subsequently zero. This solves the problem.

Note. It can even be shown that the inequality $|m-3c| < N$ holds for any $N \geq 20$.