N, D = [int(i) for i in input().split()] count = 0 for x in range(1, N + 1): for y in range(x, N + 1): for z in range(y, N + 1): t = x * x + y * y + z * z - D if t < 0: continue if t > N * N: break w = int(t ** 0.5) if t == w * w: num = len(set([x, y, z])) - 1 count += [1, 3, 6][num] print(count)