I did not understand the solution of this problem completely, like i do have some idea after reading this(https://www.geeksforgeeks.org/combinatorial-game-theory-set-2-game-nim/)
but still how it is working in this problem i could not get completely.