Problem - Stone Game IV

LC 1510 - remove square amounts

Alice and Bob play with nn stones. Each turn, remove a positive square number of stones (1,4,9,16,...1, 4, 9, 16, ...). The player who cannot move loses. Determine if Alice (first player) wins with optimal play.

Example: n=7n = 7. Alice takes 44, leaving 33. Bob takes 11, leaving 22. Alice takes 11, leaving 11. Bob takes 11, leaving 00. Alice can't move. Bob wins.