I’m unable to understand first test case with N =4, M=2.
Lets say, A will start the game with 0, now he can add any number from 1 to M. Lets say A added 2 to 0, shouts 2 and pass 2 to B.
B can add any number from 1 to M. B adds 2 to 2, resulting it in 4. He shouts 4 which is actually N. So, B must be the winner ?
And many other scenario is possible.
For 5 though, no matter what player A does, player B can capture 5.
But for 6, player A can go to 1. Now, if we calculate all possibilities of player B, it’ll be in the range 2 to 5. Now, A can add 6 minus the value B selected.
For 7, A will start at 2, then B's range would be from 3 to 6. A can add 7 minus the value B selected.
Same for 8, 9.
But for 10, B will win as B will just capture 5 after what A plays. Then A has to select a value from 6 to 9. B will just add 10 minus what A selects.
Ok, thanks, got it! Point here was A is always trying to win the game and starting first, A has an advantage. I was simply lost in case where why B can’t be a winner, neglecting the normal human behavior of winning if possible.