We’ll use sprague grundy theorem. We claim that grundy value of xxx is same as x/2x/2x/2 if xxx is even. otherwise it is (x−1)/2(x-1)/2(x−1)/2. This can be proven with induction. after that it is straightforward.