Game theory-1 solution

COULD ANYONE PLEASE GIVE ME ITS SOLUTION?

For N pile
For m stones each:
Find divisors of m
Let say a1,a2,a3…an
Grundy(m)=Mex(Grundy(a1),Grundy(a2),Grundy(a3),…)
Ans=2 if((Grundy(m)==0)||(n%2==0))
else
Ans=1
Do all these things in optimized way

Try according to given logic.After that If not able to solve then I will share u the code