from collections import defaultdict N, D = map(int, input().split()) p, n = defaultdict(int), defaultdict(int) for i in range(1, N+1): for j in range(1, N+1): p[i**2 + j**2] += 1 n[i**2 - j**2] += 1 res = 0 for key in p.keys(): res += p[key]*n[D-key] print(res)