N,D = map(int,input().split()) from collections import defaultdict # x^2 + y^2で作れる数を全列挙 XY = defaultdict(int) for x in range(1, N + 1): for y in range(1, N + 1): XY[x**2 + y ** 2] += 1 ans = 0 for z in range(1, N + 1): for w in range(1, N + 1): ans += XY[D - (z ** 2 - w ** 2)] print(ans)