#4平方定理 N,D=map(int,input().split()) from collections import defaultdict d=defaultdict(int) e=defaultdict(int) for i in range(1,N+1): for j in range(1,N+1): d[i**2+j**2]+=1 for i in range(1,N+1): for j in range(1,N+1): e[i**2-j**2+D]+=1 ans=0 bound=max(e.keys()) for key in d.keys(): if key<=bound and key in e.keys(): ans+=d[key]*e[key] print(ans)