A game has a pile of tokens, and two players alternate in taking a certain number of tokens from the pile, with the constraint that the number has to be a non-zero perfect square. A player loses if no tokens remain to be taken.
For example, if the game starts with 4 tokens in the pile, then Player 1 can win by taking all of them. If the game starts with 14 tokens, Player 1 can win by taking 9, leaving 5. Player 2 must then take either 1 or 4. Either way, Player 1 wins by taking all of the remaining tokens.
Write a function that takes the initial number of tokens in the pile and returns true if Player 1 can force a win by playing optimally.

Solution Stats

4 Solutions

4 Solvers

Last Solution submitted on Sep 25, 2025

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...