N,D=map(int,input().split()) lst=[i**2 for i in range(1,N+1)] from bisect import bisect_left as bl ans=0 for i in range(N): for j in range(N): x=lst[i]+lst[j]-D if lst[bl(lst,x)]==x: ans+=1 print(ans)