# coding: utf-8 # Your code here! N,D=map(int,input().split()) xy={} for i in range(1,N+1): for j in range(1,N+1): temp=(i**2+j**2) if temp in xy: xy[temp]+=1 else: xy[temp]=1 ans=0 for i in range(1,N+1): for j in range(1,N+1): temp=(i**2-j**2) if D-temp in xy: ans+=xy[D-temp] print(ans)