mfgnik

Untitled

Jul 23rd, 2020
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from math import sqrt, ceil
  2.  
  3.  
  4. def is_enough(width, height, amount, side):
  5.     return amount <= (side // width) * (side // height)
  6.  
  7.  
  8. def binary_search(width, height, amount):
  9.     left = 0
  10.     right = ceil(sqrt(amount)) * max(width, height)
  11.     while right - left > 1:
  12.         middle = (left + right) // 2
  13.         if is_enough(width, height, amount, middle):
  14.             right = middle
  15.         else:
  16.             left = middle
  17.     return right
  18.  
  19.  
  20. print(binary_search(*map(int, input().split())))
Advertisement
Add Comment
Please, Sign In to add comment