Brick by Brick
You are given an an infinite box of bricks where each brick has dimension a×b. By placing bricks side by side, you can construct a rectangle.
You are asked to construct a series of n rectangles. Each rectangle must have some length-to-width ratio 1:mi. For each rectangle, determine the minimum number of bricks you'd need to construct such a rectangle.
Input
The first line contains an integer n, the number of rectangles you need to construct.
The second line contains two space-integers a and b representing the dimensions of the bricks.
The next n lines each contain a single integer mi representing the ratio of the rectangle you need to construct.
Output
For each 1≤i≤n, output the minimum number of bricks needed to construct a rectangle with a length-to-width ratio of 1:mi.
Constraints
- 1≤a,b≤1000
- 1≤m≤109
Example 1
3
2 3
1
2
5
6
3
30
Explanation
Each brick has dimension 2×3.
The first query 1 asks you to construct a rectangle with a length-to-width ratio of 1:1. 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 6×6, which is in a 1:1 ratio.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.