Problem

Source: 2022 Centroamerican and Caribbean Mathematical Olympiad, P1

Tags: game strategy, combinatorics



There is a pile with 2022 rocks. Ana y Beto play by turns to the following game, starting with Ana: in each turn, if there are $n$ rocks in the pile, the player can remove $S(n)$ rocks or $n-S(n)$ rocks, where $S(n)$ is the sum of the the digits of $n$. The person who removes the last rock wins. Determine which of the two players has a winning strategy and describe it.