K,N=map(int,input().split()) ans=set() x=1 y=1 while x**6<=N-y**4: while y**4<=N-x**6: t=x**6+y**4 if t<=10**15 and t%K==0 and ((t//K)**0.5).is_integer(): ans.add(t) y+=1 x+=1 y=1 print(len(ans))