K,N=map(int,input().split()) ok=True ans=[] for x in range(1,100000000): if x**6>N: break for y in range(1,1000000000): if x**6+y**4>N: break #x**6+y**4が条件を満たすか判定 a=x**6+y**4 if a%K!=0: continue a//=K ok=0 ng=1000000000 while abs(ok-ng)>1: mid=(ok+ng)//2 if mid*mid<=a: ok=mid else: ng=mid if ok*ok==a: ans.append(ok*ok) if not ok: break print(len(set(ans)))