def solve(): N, D = map(int, input().split()) p = [] c = [0] * 8000001 for i in range(1, N + 1): p.append(i**2) for i in p: for j in p: s = i - j + D if s >= 1: c[s] += 1 res = 0 for i in p: for j in p: res += c[i + j] print(res) solve()