import sys def main(): input_line = sys.stdin.readline().strip() N, D = map(int, input_line.split()) max_sum_xy = 2 * N * N sum_counts = [0] * (max_sum_xy + 1) # Precompute x squares x_sqs = [x * x for x in range(N + 1)] # Fill sum_counts with counts of x^2 + y^2 for x in range(1, N + 1): x_sq = x_sqs[x] for y in range(1, N + 1): s = x_sq + y * y if s <= max_sum_xy: sum_counts[s] += 1 # Precompute z squares z_sqs = [z * z for z in range(N + 1)] ans = 0 for w in range(1, N + 1): t = w * w + D temp = 0 for z in range(1, N + 1): a = t - z_sqs[z] if 2 <= a <= max_sum_xy: temp += sum_counts[a] ans += temp print(ans) if __name__ == "__main__": main()