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