



"""simple docstring"""
from __future__ import annotations

from math import ceil, floor, sqrt


def 	_SCREAMING_SNAKE_CASE  (__lowerCAmelCase = 2_00_00_00							)       ->  int:







  '''simple docstring'''


  lowercase_	    =       [0]
  lowercase_	    =       42

  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_	    =       0
  # the area corresponding to the grid that gives the product closest to target
  lowercase_	    =       0
  # an estimate of b, using the quadratic formula
  lowercase_	    =       42
  # the largest integer less than b_estimate
  lowercase_	    =       42
  # the largest integer less than b_estimate
  lowercase_	    =       42
  # the triangle number corresponding to b_floor
  lowercase_	    =       42
  # the triangle number corresponding to b_ceil
  lowercase_	    =       42

  for idx_a, triangle_a in enumerate(triangle_numbers[1:]       ,     1							):
    lowercase_	    =       (-1 + sqrt(1 + 8 * target / triangle_a							)) / 2
    lowercase_	    =       floor(UpperCamelCase__							)
    lowercase_	    =       ceil(UpperCamelCase__							)
    lowercase_	    =       triangle_numbers[b_floor]
    lowercase_	    =       triangle_numbers[b_ceil]

    if abs(target - triangle_b_first_guess * triangle_a							) < abs(
        target - best_product							):
      lowercase_	    =       triangle_b_first_guess * triangle_a
      lowercase_	    =       idx_a * b_floor

    if abs(target - triangle_b_second_guess * triangle_a							) < abs(
        target - best_product							):
      lowercase_	    =       triangle_b_second_guess * triangle_a
      lowercase_	    =       idx_a * b_ceil

  return area


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







from dataclasses import dataclass
from typing import Tuple

import numpy as np
import torch







@dataclass
class     __lowerCAmelCase :

			"""simple docstring"""







			snake_case_   		=       42  # [batch_size x 3]
			snake_case_   		=       42  # [batch_size x 3]
			snake_case_   		=       42  # [batch_size x 3]
			snake_case_   		=       42  # [batch_size x 3]
			snake_case_   		=       42
			snake_case_   		=       42
			snake_case_   		=       42
			snake_case_   		=       42
			snake_case_   		=       42


			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							assert self.x.shape[0] == self.y.shape[0] == self.z.shape[0] == self.origin.shape[0]
							assert self.x.shape[1] == self.y.shape[1] == self.z.shape[1] == self.origin.shape[1] == 3
							assert len(self.x.shape							) == len(self.y.shape							) == len(self.z.shape							) == len(self.origin.shape							) == 2


			def       lowercase_    (      self							)    ->      Optional[int]:



							'''simple docstring'''
							return torch.from_numpy(np.array([self.width, self.height]			,						dtype=np.floataa							)							)


			def       lowercase_    (      self							)    ->      Optional[Any]:



							'''simple docstring'''
							return torch.from_numpy(np.array([self.x_fov, self.y_fov]			,						dtype=np.floataa							)							)


			def       lowercase_    (      self							)    ->      torch.Tensor:



							'''simple docstring'''
							__lowerCamelCase		       =    torch.arange(self.height * self.width							)
							__lowerCamelCase		       =    torch.stack(
							    [
							        pixel_indices % self.width,
							        torch.div(lowerCamelCase__			,						self.width			,						rounding_mode='trunc'							),
							    ]			,						axis=1			,						)
							return coords


			@property
			def       lowercase_    (      self							)    ->      int:



							'''simple docstring'''
							__lowerCamelCase       ,						*__lowerCamelCase		       =    self.shape
							__lowerCamelCase		       =    int(np.prod(lowerCamelCase__							)							)

							__lowerCamelCase		       =    self.get_image_coords()
							__lowerCamelCase		       =    torch.broadcast_to(coords.unsqueeze(0							)			,						[batch_size * inner_batch_size, *coords.shape]							)
							__lowerCamelCase		       =    self.get_camera_rays(lowerCamelCase__							)

							__lowerCamelCase		       =    rays.view(lowerCamelCase__			,						inner_batch_size * self.height * self.width			,						2			,						3							)

							return rays


			def       lowercase_    (      self			,						lowerCamelCase__							)    ->      torch.Tensor:



							'''simple docstring'''
							__lowerCamelCase       ,						*__lowerCamelCase       ,						__lowerCamelCase		       =    coords.shape
							assert n_coords == 2
							assert batch_size == self.origin.shape[0]

							__lowerCamelCase		       =    coords.view(lowerCamelCase__			,						-1			,						2							)

							__lowerCamelCase		       =    self.resolution()
							__lowerCamelCase		       =    self.fov()

							__lowerCamelCase		       =    (flat.float() / (res - 1)) * 2 - 1
							__lowerCamelCase		       =    fracs * torch.tan(fov / 2							)

							__lowerCamelCase		       =    fracs.view(lowerCamelCase__			,						-1			,						2							)
							__lowerCamelCase		       =    (
							    self.z.view(lowerCamelCase__			,						1			,						3							)
							    + self.x.view(lowerCamelCase__			,						1			,						3							) * fracs[:, :, :1]
							    + self.y.view(lowerCamelCase__			,						1			,						3							) * fracs[:, :, 1:]
							)
							__lowerCamelCase		       =    directions / directions.norm(dim=-1			,						keepdim=lowerCamelCase__							)
							__lowerCamelCase		       =    torch.stack(
							    [
							        torch.broadcast_to(self.origin.view(lowerCamelCase__			,						1			,						3							)			,						[batch_size, directions.shape[1], 3]							),
							        directions,
							    ]			,						dim=2			,						)
							return rays.view(lowerCamelCase__			,						*lowerCamelCase__			,						2			,						3							)






			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      "DifferentiableProjectiveCamera":



							'''simple docstring'''
							assert width * self.height == height * self.width, "The aspect ratio should not change."
							return DifferentiableProjectiveCamera(
							    origin=self.origin			,						x=self.x			,						y=self.y			,						z=self.z			,						width=lowerCamelCase__			,						height=lowerCamelCase__			,						x_fov=self.x_fov			,						y_fov=self.y_fov			,						)







def 			lowerCamelCase_		(       UpperCamelCase__				:      int      )     ->       DifferentiableProjectiveCamera:





				"""simple docstring"""


				__lowerCamelCase		       =    []
				__lowerCamelCase		       =    []
				__lowerCamelCase		       =    []
				__lowerCamelCase		       =    []
				for theta in np.linspace(0 ,     2 * np.pi ,     num=20      ):
								__lowerCamelCase		       =    np.array([np.sin(UpperCamelCase__      ), np.cos(UpperCamelCase__      ), -0.5]      )
								z /= np.sqrt(np.sum(z**2      )      )
								__lowerCamelCase		       =    -z * 4
								__lowerCamelCase		       =    np.array([np.cos(UpperCamelCase__      ), -np.sin(UpperCamelCase__      ), 0.0]      )
								__lowerCamelCase		       =    np.cross(UpperCamelCase__ ,     UpperCamelCase__      )
								origins.append(UpperCamelCase__      )
								xs.append(UpperCamelCase__      )
								ys.append(UpperCamelCase__      )
								zs.append(UpperCamelCase__      )
				return DifferentiableProjectiveCamera(
				    origin=torch.from_numpy(np.stack(UpperCamelCase__ ,     axis=0      )      ).float() ,     x=torch.from_numpy(np.stack(UpperCamelCase__ ,     axis=0      )      ).float() ,     y=torch.from_numpy(np.stack(UpperCamelCase__ ,     axis=0      )      ).float() ,     z=torch.from_numpy(np.stack(UpperCamelCase__ ,     axis=0      )      ).float() ,     width=UpperCamelCase__ ,     height=UpperCamelCase__ ,     x_fov=0.7 ,     y_fov=0.7 ,     shape=(1, len(UpperCamelCase__      )) ,     )


