Yes, this challenge could have been brute forced easily, but the maths behind it is nice :)

Solution


Let's consider the first few n.

If n=1, Alice wins because she just takes the one stone.

If n=2, Alice can again just take both stones because 2 is prime.

If n=3, Alice wins in the same way.

If n=4, Alice can take 1 or 2 stones but there will be either 2 or 3 stones left, and in both cases Bob can take all the remaining stones, so Alice loses.

In other words:

If n=1, the player who goes first in this situation wins.

If n=2, the player who goes first in this situation wins.

If n=3, the player who goes first in this situation wins.

If n=4, the player who goes first in this situation must reduce n to a non-zero number smaller than 4, but in all of these cases we know that the player who goes first in that situation wins, so here the player who goes first for n=4 loses.

If n=5, the player who goes first in this situation can reduce n to 4 which is a known situation where the player who goes first in that situation loses, so the player who goes first for n=5 wins.

We can construct a table for n. If the player who goes first in that situation wins, we place a "Y" in the table, else we place a "N". We can see that if Alice can reduce the initial value of n to a value of n that is stored as "N" in the table, then Alice can force a win (so a Y is placed), otherwise Bob can win (so an N is placed)

(n=0: N)

n=1: Y

n=2: Y