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