Redaksiya
Let be the required length of the side of the square board. Search for using binary search. Obviously, . Start the search in the interval .
Let be the current length of the side of the board. Since the diploma has a size of , the board can accommodate a maximum of diplomas. If this number is less than , then the board size is too small, and we set . Otherwise, we move the right search boundary: .
Let the size of the diploma is .
On a board, you can place a maximum of diplomas;
On a board, you can place a maximum of diplomas;
The minimum size of the board’s side, where you can place diplomas, is .
Algorithm realization
Read the input data.
scanf("%lld %lld %lld", &w, &h, &n);
Set the boundaries of the binary search to .
a = 0; b = max(w, h) * n;
Start the binary search.
while (a < b) { m = (a + b) / 2;
The maximum number of diplomas of size that can be arranged on the board with side length is .
dip = (m / w) * (m / h); if (dip < n) a = m + 1; else b = m; }
Print the answer.
printf("%lld\n", b);
Python realization
Read the input data.
w, h, n = map(int, input().split())
Set the boundaries of the binary search to .
a = 0 b = max(w, h) * n
Start the binary search.
while a < b: m = (a + b) // 2
The maximum number of diplomas of size that can be arranged on the board with side length is .
dip = (m // w) * (m // h) if dip < n: a = m + 1 else: b = m
Print the answer.
print(b)