Familiarity with Sprague–Grundy theorem should be helpful in solving the problem.