N,D=map(int, input().split()) Square = [] P = [0]*(2000**2*2+5) for i in range(N+1): Square.append(i**2) for i in range(1,N+1): for j in range(1,N+1): P[Square[i]+Square[j]]+=1 ans = 0 for i in range(1,N+1): for j in range(1,N+1): temp = Square[i]-Square[j]+D if temp >=0: ans += P[temp] print(ans)