Wrong outputs in Game of Stones using Grundy numbers

ques:
https://hack.codingblocks.com/contests/c/547/1150
code:
https://ide.codingblocks.com/s/55397

I am getting wrong outputs, can you pls correct my mistake

Many Problems in your code:
for n==1 answer would be 0.
and you are calculating
grundy(n-2)^grundy(n-3)^grundy(n-5) !=0 //For First winning.

Correct approach
just find Grundy(n)=Mex(Grundy(n-2) , Grundy (n-3) , Grundy(n-5) ).
if(Grundy(n)!=0) //First Wins

https://ide.codingblocks.com/s/55579
Refer my code :slight_smile:

1 Like

Got it thank you very much