5. On the table, there are 40 red and 50 green stones. Two players, Petya and Vasya, take turns: on each turn, a player chooses a color and removes an arbitrary number of stones of that color, which must be a divisor of the number of stones of the other color at the moment of the move (zero is divisible by any natural number). The player who takes the last stone wins. Who among them has a guaranteed chance to win if Petya goes first? (I. A. Sheypak)
Answer: Petya.

Solution. Let at some point there are $a$ red and $b$ green stones on the table. Then:

(1) if $a$ and $b$ have different parity, the player to move wins, because if the even number is 0, then for the win, he just needs to take the remaining stones (their number - a divisor of zero), and if both numbers are not 0, then he subtracts 1 from the even number (definitely - a divisor of the other number) and comes to the next situation (2), when both numbers are odd;

(2) if $a$ and $b$ are odd, the player to move loses, because he is forced to subtract an odd number (a divisor of an odd number) from one of the odd numbers and get an even number, that is, create a situation from (1), which is winning for the opponent;

(3) if $a$ and $b$ are even, then each player is forced to take an even number of stones, otherwise he creates a situation (1), which is winning for the opponent. Therefore, we can consider not the stones, but pairs of stones, and the solution of the problem for $(2a, 2b)$ is equivalent to the solution of the problem for $(a, b)$. This is exactly the situation given in the condition, where $a=20, b=25$, so the problem reduces to case (2) and Petya wins;

(4) for completeness, note that by applying the idea from point (3) several times, we get that generally, if $a=2^{k} \alpha$ and $b=2^{k} \beta$, where $k, \alpha, \beta \in \mathbb{N}$, then with both $\alpha, \beta$ odd, the starting player loses, and with exactly one odd, he wins.

## Team Olympiad

## Junior League