Problem

Source: Argentina Cono Sur TST 2014, Problem 1

Tags: number theory proposed, number theory



A positive integer $N$ is written on a board. In a step, the last digit $c$ of the number on the board is erased, and after this, the remaining number $m$ is erased and replaced with $|m-3c|$ (for example, if the number $1204$ is on the board, after one step, we will replace it with $120 - 3 \cdot 4 = 108$). We repeat this until the number on the board has only one digit. Find all positive integers $N$ such that after a finite number of steps, the remaining one-digit number is $0$.