n, d = [int(i) for i in input().rstrip().split()] sqr = [i**2 for i in range(n + 1)] target_num_lis = [i + d for i in sqr] max_num = target_num_lis[-1] count = 0 for x in range(1, n + 1): sqr_x = sqr[x] if sqr_x > max_num: break for y in range(x, n + 1): sqr_xy = sqr_x + sqr[y] if sqr_xy > max_num: break for z in range(y, n + 1): sqr_xyz = sqr_xy + sqr[z] if sqr_xyz in target_num_lis: w = target_num_lis.index(sqr_xyz) if x != y != z: count += 6 elif x == y == z: count += 1 else: count +=3 # print('x:{0} y:{1} z:{2} in w{3}'.format(x,y,z,w)) # print('count = ' + str(count)) # input() print(count)