from collections import defaultdict # from time import time # start = time() N, D = map(int, input().split()) cnt_1, cnt_2 = defaultdict(int), defaultdict(int) for x in range(1, N + 1): cnt_1[2 * x**2 - D] += 1 cnt_2[0] += 1 for y in range(x + 1, N + 1): cnt_1[x**2 + y**2 - D] += 2 cnt_2[x**2 - y**2] += 1 cnt_2[y**2 - x**2] += 1 # print(time() - start) ans = 0 for key, value in cnt_1.items(): if key in cnt_2: ans += value * cnt_2[key] print(ans)