K,N=map(int,input().split()) x=[] cur=1 while cur**4<=N: x.append(cur**4) cur+=1 y=[] cur=1 while cur**6<=N: y.append(cur**6) cur+=1 # print(x,y) import math v=[] for a in x: for b in y: if a+b<=N: z2=(a+b)//K z=math.isqrt(z2) if z*z*K==a+b: v.append(a+b) # print(a,b,z) print(len(set(v)))