N,D=map(int,input().split()) c=dict() n=[i**2 for i in range(1,N+1)] for i in range(1,1+N): for j in range(1,1+N): a=n[i-1]+n[j-1] if a in c: c[a]+=1 else: c[a]=1 m=dict() for i in range(1,1+N): for j in range(1,1+N): a=n[i-1]-n[j-1] if a in m: m[a]+=1 else: m[a]=1 ans=0 for i in c: k=D-i if k in m: ans+=m[k]*c[i] print(ans)