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