n,z=map(int,input().split()) if n==1: print(z-1) else: a=0 for x in range(1,30): if x>=z: break for y in range(1,30): if y>=z: break a+=x**n+y**n==z**n print(a)