link to the following questions: hard1499-1739
To get if the first player can remove the last stone if two players take turns to remove #square number stones. Let the function denote whether the current player is guaranteed to win or not if there are n stones left If the current player is the winner, the next player is not guaranteed to win in some of the next state.
def dfs(n):
i = 1
while n-i**2 >= 0:
# get next state
if next player can not win in this state,then return true
i += 1