# 公式解説より # 2重ループは可能、を押し進めるべきだった # x, yで作れる数を全探索 # w, D, zで作れる数を全探索 # その組合せ数が答え N, D = map(int, input().split()) from collections import defaultdict xy = defaultdict(int) wDz = defaultdict(int) for x in range(1, N+1): for y in range(1, N+1): calc1 = x**2+y**2 xy[calc1] += 1 calc2 = x**2+D-y**2 wDz[calc2] += 1 ans = 0 for num in xy: ans += xy[num]*wDz[num] print(ans)