Problem J
Tile Cutting
-
The rectangular tile to be cut must be positioned in the bottom left corner of the cutting surface and the edges must be aligned with the grid lines.
-
The cutting blade can cut along any line connecting two different grid points on the tile boundary as long as the points are on adjacent boundary edges.
-
The four corners of the resulting parallelogram tile must lie on the four sides of the original rectangular tile.
-
No edge of the parallelogram tile can lie along an edge of the rectangular tile.
Figure 1 shows the eight different ways in which a parallelogram tile of area $4$ square centimeters can be cut out of a rectangular tile, subject to these restrictions.
Youssef needs to cut tiles of every area between $a_{\text {lo}}$ and $a_{\text {hi}}$. Now he wonders, for which area $a$ in this range can he cut the maximum number of different tiles?
Input
The input consists of multiple test cases. The first line of input contains an integer $n$ ($1 \le n \le 500$), the number of test cases. The next $n$ lines each contain two integers $a_{\text {lo}}, a_{\text {hi}}$ ($1 \le a_{\text {lo}} \le a_{\text {hi}} \le 500\, 000$), the range of areas of the tiles.
Output
For each test case $a_{\text {lo}}$, $a_{\text {hi}}$, display the value $a$ between $a_{\text {lo}}$ and $a_{\text {hi}}$ such that the number of possible ways to cut a parallelogram of area $a$ is maximized as well as the number of different ways $w$ in which such a parallelogram can be cut. If there are multiple possible values of $a$ display the smallest one.
Sample Input 1 | Sample Output 1 |
---|---|
2 4 4 2 6 |
4 8 6 20 |