Comments

A better way to understand these problems is through Grundy numbers and the Sprague–Grundy theorem, which are fundamental concepts in combinatorial game theory.

They are particularly useful for solving impartial games.Games in which both players have exactly the same legal moves from any given position.

The main idea is that instead of analysing the entire game state and all possible sequences of moves, we can assign a number (called a Grundy number) to each independent component of the game.

We can then combine these numbers using XOR to determine whether the current position is winning or losing.

After reading about this the solution given in tutorial definitely make sense to you.

But yes it's somewhat advanced concept but it's always better to have more knowledge.

in problem c can we use priority queue like this computed all the consecutive differences ( for even [0,1],[2,3]...like this and for odd last difference is pushed (n-1 and n-2)to priority queue when priority queue only task is to divide the maximum if even to half-half and for odd half-half+1 and pushed again and do this for x iteration but getting wrong answer.is this idea correct?

396268679

edit: Got it