Brick by Brick
View as PDFYou are given an an infinite box of bricks where each brick has dimension . By placing bricks side by side, you can construct a rectangle.
You are asked to construct a series of rectangles. Each rectangle must have some length-to-width ratio
. For each rectangle, determine the minimum number of bricks you'd need to construct such a rectangle.
Input
The first line contains an integer , the number of rectangles you need to construct.
The second line contains two space-integers and
representing the dimensions of the bricks.
The next lines each contain a single integer
representing the ratio of the rectangle you need to construct.
Output
For each , output the minimum number of bricks needed to construct a rectangle with a length-to-width ratio of
.
Constraints
Example 1
Input
3
2 3
1
2
5
Output
6
3
30
Explanation
Each brick has dimension .
The first query 1 asks you to construct a rectangle with a length-to-width ratio of . We can do this with 6 bricks:
111222
111222
333444
333444
555666
555666
where each distinct number represents a particular brick (for example, all the 1s represent the first brick). This resulting rectangle has dimension , which is in a
ratio.
Comments