import sys from collections import defaultdict def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,D = MI() count = defaultdict(int) for i in range(1,N+1): for j in range(i,N+1): a = i**2+j**2 if i == j: count[a] += 1 else: count[a] += 2 ans = 0 for i in range(1,N+1): for j in range(1,N+1): b = -i**2+j**2+D if b >= 2: ans += count[-i**2+j**2+D] print(ans)