from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,D = map(int,input().split()) A = defaultdict(int) for i in range(1,N+1): i2 = i*i for j in range(1,N+1): j2 = j*j A[D + i2 - j2] += 1 ans = 0 for i in range(1,N+1): i2 = i*i for j in range(1,N+1): j2 = j*j ans += A[i2+j2] print(ans)