General solution to this kind of problem


  • 1
    H

     inspired by all 4s shall be false,I generalize the problem to n stones that you can take at once among m stones. it becomes very easy after we find out all the death numbers.

     Firstly,when we have stones less than or equals n,we are definitely winning. So obviously n+1 is a death number because you cannot take all the stones at once and the remaining stones can all be taken by the opponent. What is the next death number? When we have 2n+2 stones,no matter how many stones you take(assume i,where 1<=i<=n),your opponent can take j stones(1<=j<=n) to make i+j = n+1,so the number reduces to n+1,and it's your turn to meet the death number. So 2n+2 is also a death number.Now we can say:all multiples of n+1 are death numbers.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.