Rectangle and Squares
Time limit2sMemory limit512 MB
Given target area A*B and a square size C, find the rectangle of side C that is closest in area to A*B, breaking ties toward the smaller area.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Brute force, Implementation
- Solved
- No attempts yet
Problem
Elijah visited his friend Phil and saw a rectangle with sides and . Elijah had wanted a rectangle of that area for a long time.
Back home, Elijah found that he owns a large number of squares of size . He wants to build a rectangle out of those squares whose area is as close as possible to the area of Phil's rectangle. In other words, he wants to minimize the absolute difference between the two areas.
Elijah puts the squares down with their sides parallel, without gaps and without overlaps. He uses at least one square.
For example, if Phil's rectangle is and Elijah's squares are , the rectangle with the closest area that Elijah can build is .
Input
The first line contains the number of test cases ().
Each of the next lines contains three integers , and ().
Output
For each test case print one line with the area of the rectangle Elijah builds.
If several areas are equally close to the area of Phil's rectangle, print the smallest of them.