Subtraction Game Problem (Jan Cook-off)

What concept of game theory is used to solve this problem?
I found total steps taken for each pair of numbers to become equal and then checked whether it was odd or even, however this method TLE’d.

I think Editorial will be published soon. Anyway, I used Sprague–Grundy_theorem to solve it.

Just found this:
Topcoder Tutorial for Algorithmic Games

Read the ‘Game of Nim’ part.

Yes you need to use Sprague Grundy Theorem. My editorial had some errors and was not properly explained. I will post it in couple of hours time.

That’s ok, I’ve posted a Topcoder link that provides a sufficient explanation I think.