


from __future__ import annotations

from scipy.special import comb  # type: ignore






class _lowerCamelCase:
       def __init__(					self,      lowerCamelCase)       ->   Tuple:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		list_of_points
           # Degree determines the flexibility of the curve.
           # Degree = 1 will produce a straight line.
           _lowercase       :							List[str]      		=		len(lowerCamelCase) - 1
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   list[float]:




           """simple docstring"""

           assert 0 <= t <= 1, "Time t must be between 0 and 1."
           _lowercase       :							list[float]      		=		[]
           for i in range(len(self.list_of_points)):
               # basis function for each i
               output_values.append(
                   comb(self.degree,      lowerCamelCase) * ((1 - t) ** (self.degree - i)) * (t**i))
           # the basis must sum up to 1 for it to produce a valid Bezier curve.
           assert round(sum(lowerCamelCase),      5) == 1
           return output_values
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   tuple[float, float]:




           """simple docstring"""

           assert 0 <= t <= 1, "Time t must be between 0 and 1."

           _lowercase       :							Optional[int]      		=		self.basis_function(lowerCamelCase)
           _lowercase       :							Optional[int]      		=		0.0
           _lowercase       :							Optional[Any]      		=		0.0
           for i in range(len(self.list_of_points)):
               # For all points, sum up the product of i-th basis function and i-th point.
               x += basis_function[i] * self.list_of_points[i][0]
               y += basis_function[i] * self.list_of_points[i][1]
           return (x, y)




       def 			UpperCamelCase     (					self,      lowerCamelCase = 0.0_1)       ->   int:




           """simple docstring"""

           from matplotlib import pyplot as plt  # type: ignore

           _lowercase       :							list[float]      		=		[]  # x coordinates of points to plot
           _lowercase       :							list[float]      		=		[]  # y coordinates of points to plot

           _lowercase       :							str      		=		0.0
           while t <= 1:
               _lowercase       :							List[Any]      		=		self.bezier_curve_function(lowerCamelCase)
               to_plot_x.append(value[0])
               to_plot_y.append(value[1])
               t += step_size

           _lowercase       :							List[str]      		=		[i[0] for i in self.list_of_points]
           _lowercase       :							Dict      		=		[i[1] for i in self.list_of_points]

           plt.plot(
               lowerCamelCase,      lowerCamelCase,      color='blue',      label='Curve of Degree ' + str(self.degree),      )
           plt.scatter(lowerCamelCase,      lowerCamelCase,      color='red',      label='Control Points')
           plt.legend()
           plt.show()


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 BezierCurve([(1, 2), (3, 5)]).plot_curve()  # degree 1
 BezierCurve([(0, 0), (5, 5), (5, 0)]).plot_curve()  # degree 2
 BezierCurve([(0, 0), (5, 5), (5, 0), (2.5, -2.5)]).plot_curve()  # degree 3






from __future__ import annotations

from math import ceil, floor, sqrt



def 				UpperCamelCase_(      lowerCamelCase_ = 200_0000 )    ->						int:
    _lowercase       :							list[int]      		=		[0]
    _lowercase       :							int

    for idx in range(1							, ceil(sqrt(target * 2 ) * 1.1 ) ):
        triangle_numbers.append(triangle_numbers[-1] + idx )

    # we want this to be as close as possible to target
    _lowercase       :							int      		=		0
    # the area corresponding to the grid that gives the product closest to target
    _lowercase       :							int      		=		0
    # an estimate of b, using the quadratic formula
    _lowercase       :							float
    # the largest integer less than b_estimate
    _lowercase       :							int
    # the largest integer less than b_estimate
    _lowercase       :							int
    # the triangle number corresponding to b_floor
    _lowercase       :							int
    # the triangle number corresponding to b_ceil
    _lowercase       :							int

    for idx_a, triangle_a in enumerate(triangle_numbers[1:]							, 1 ):
        _lowercase       :							Optional[int]      		=		(-1 + sqrt(1 + 8 * target / triangle_a )) / 2
        _lowercase       :							List[str]      		=		floor(lowerCamelCase_ )
        _lowercase       :							Dict      		=		ceil(lowerCamelCase_ )
        _lowercase       :							List[str]      		=		triangle_numbers[b_floor]
        _lowercase       :							List[str]      		=		triangle_numbers[b_ceil]

        if abs(target - triangle_b_first_guess * triangle_a ) < abs(
            target - best_product ):
            _lowercase       :							Union[str, Any]      		=		triangle_b_first_guess * triangle_a
            _lowercase       :							Union[str, Any]      		=		idx_a * b_floor

        if abs(target - triangle_b_second_guess * triangle_a ) < abs(
            target - best_product ):
            _lowercase       :							Any      		=		triangle_b_second_guess * triangle_a
            _lowercase       :							Optional[Any]      		=		idx_a * b_ceil

    return area


if __name__ == "__main__":
 print(F"{solution() = }")


