A bakery cuts square cookies of whole-number side s from shortbread sheets (w, h); one sheet yields (w // s) * (h // s) cookies, and leftovers are thrown away.
Write biggest_side(sheets: list[tuple[int, int]], need: int) -> int that returns the largest s for which all sheets together yield at least need cookies, or 0 if even s = 1 falls short.
biggest_side([(10, 7), (4, 4)], 5) # 3 (s = 3 gives 3*2 + 1*1 = 7 cookies; s = 4 gives only 3)
biggest_side([(10, 7), (4, 4)], 3) # 4
biggest_side([(2, 3)], 7) # 0 (only 6 unit squares exist)
Up to 10^4 sheets, sides up to 10^9, need up to 10^18. In C++/Java, stop adding once you reach need, or the count overflows. ⭐ Bonus: a speed test with huge sheets earns a star for binary search.
Show hint
the count only drops as s grows. Binary search for the last s that still works.