N,D=map(int,input().split()) lst=[i**2 for i in range(1,N+1)] cnt=[0]*(8*10**6+3) for i in range(N): for j in range (i,N): if i==j: cnt[lst[i]+cnt[j]]+=1 else: cnt[lst[i]+lst[j]]+=2 ans=0 for i in range(N): x=lst[i]+D for j in range (N): ans+=cnt[x-lst[j]] print(ans)