n, d = map(int, input().split()) li1 = {} for x in range(1, n + 1): for y in range(1, n + 1): if x**2 + y**2 not in li1: li1[x**2 + y**2] = 1 else: li1[x**2 + y**2] += 1 ans = 0 for i in range(1, n + 1): for j in range(1, n + 1): if d + i**2 - j**2 in li1: ans += li1[d + i**2 - j**2] print(ans)