k, n = map(int, input().split()) x = 1 C = set() while x ** 6 + 1 <= n: y = 1 while x ** 6 + y ** 4 <= n: C.add(x**6+y**4) y += 1 x += 1 ans = 0 for c in C: if c % k: continue t = c // k m = int(t**0.5) if m * m == t: ans += 1 print(ans)