import math K, N = map(int, input().split()) st = set() x = 1 while True: x6 = x**6 if x6 > N: break y = 1 while True: y4 = y**4 n = x6 + y4 if n > N: break if n % K == 0: m = n // K z = math.isqrt(m) if z**2 == m: st.add(n) y += 1 x += 1 print(len(st))