N,D = map(int, input().split()) from collections import defaultdict # cnt = defaultdict(int) 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): cnt[ lst[i] + lst[j] ] += 1 ans = 0 for i in range(N): for j in range(N): x,y = lst[i], lst[j] if y+D-x >= 1: ans += cnt[ y+D - x ] print(ans)