eolymp
bolt
Try our new interface for solving problems
Problems

Cake Division

Cake Division

You have a rectangular cake of a given length and width, and want to divide it into a certain number of equal-area rectangular pieces. Each cut you make must be parallel to the sides of the cake, and must completely cut one of the existing pieces into two parts. (Therefore, cutting the cake into \textbf{n} pieces will require exactly \textbf{n} - \textbf{1} cuts.) You prefer square pieces to those with a larger aspect ratio. (Here, we define the "aspect ratio" of a piece to be the length of its longer side divided by the length of its shorter side.) You should cut the cake in such a way as to minimize the maximum aspect ratio of all the resulting pieces. For example, if the cake is \textbf{2}x\textbf{3}, and you want to cut it into six pieces, you can cut it into six \textbf{1}x\textbf{1} pieces. Each piece has an aspect ratio of \textbf{1.0}, which is the smallest possible aspect ratio. Therefore, this solution is optimal. One way to cut a \textbf{5}x\textbf{5} cake into \textbf{5} pieces is to first cut it into two pieces of sizes \textbf{2}x\textbf{5} and \textbf{3}x\textbf{5}. Cut the smaller of these two in half (each of size \textbf{2} x \textbf{5/2}) and the larger in thirds (each of size \textbf{3} x \textbf{5/3}). The largest aspect ratio of these five pieces is \textbf{3}/(\textbf{5/3}) = \textbf{1.8}. There is no way to cut this cake into \textbf{5} equal-area pieces that all have an aspect ratio of less than \textbf{1.8}. \InputFile Consists of multiple test cases. Each test case is given in one line and contains three integers: \textbf{length} and \textbf{width} of a cake, and the number of rectangular \textbf{pieces} you must divide the cake. It is known that \textbf{1} ≤ \textbf{length}, \textbf{width ≤} \textbf{1000}, \textbf{1} ≤ \textbf{pieces ≤} \textbf{10}. \OutputFile Cut the cake to minimize the maximum aspect ratio of all the resulting pieces. For each test case print on a separate line this aspect ratio with \textbf{4} digits after the decimal point.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2 3 6
5 5 5
950 430 9
Output example #1
1.0000
1.8000
1.2573