Solving Problem , I got recurrence as f(n)= ((n+1)/2) + (n-1) ,here ~ denotes negation, f(x) is 0 if player with x stones loose and 1 if player left with x stones wins.As n can be high as 1018 so matrix exponentiation would do this,
| ~ ~ | x | f(n) | = | f(n+1) | | 1 0 | | f(n/2+1) | | f(n) |
but I am unable to do algebra with this ~ operation.