from collections import defaultdict N, D = map(int, input().split()) YZ = defaultdict(int) WDX = defaultdict(int) for i in range(1, N + 1): for j in range(1, N + 1): YZ[i * i + j * j] += 1 WDX[D + i * i - j * j] += 1 ans = 0 for yz in range(2 * N**2 + 1): ans += YZ[yz] * WDX[yz] print(ans)