Two players alternate turns taking either $a$ or $b$ stones from a pile of $n$ stones. The first player who cannot move loses. Player 1 is the player who goes first and Player 2 is the player who goes second. What conditions (in terms of $a$ and $b$) do $n$ need to satisfy if Player 2 wins (i.e. $n$ is congruent to what numbers modulo some number)?
I have tried to do this experimentally with a program, but that wasn't sustainable as I started to generalize the conditions for $n.$ I also tried to approach the problem intuitively by thinking about the players' strategies, which got messy quickly. At this point, I have been trying the problem for several months, and would like a concrete answer and solution. Thanks in advance!
A player can always make sure that the last two turns remove $a+b$ stones. If we assume $a \lt b$ then any position with less than $a$ stones wins for the last player. This means that any position with less than $a$ stones $\bmod (a+b)$ is a win for the last player. Positions with less than $b$ stones can only have $a$ removed at a time, so will depend on how many lots of $a$ can be removed. Positions with $b$ or more but less than $a+b$ are wins for the next player, who can take $b$.