Solar Panels
Time limit1sMemory limit256 MB
You pick a width and a height from the given ranges to make their greatest common divisor as large as possible.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
Byteasar decided to invest in renewable energy and opened a solar panel factory. Within a few days clients came in. Each client ordered one rectangular panel and gave a range for its width and a range for its height.
A panel is filled with square photovoltaic cells. A cell side length can be any positive integer, but all cells in one panel have the same side length. The larger the cells, the more efficient the panel, so for every order Byteasar wants the largest cell side length he can use.
For the -th order the width is chosen as an integer in and the height as an integer in . A panel of width and height can be filled with cells of side length exactly when divides both and .
Input
The first line contains one integer (), the number of ordered panels.
Each of the next lines describes one panel and contains four integers , , , separated by single spaces (, ). In order, they are the minimum width, the maximum width, the minimum height, and the maximum height of the -th panel.
Output
Print exactly lines. Line contains the largest cell side length that the -th panel can be made of.
Hint
In the first example Byteasar builds panels of size (one cell), (two cells), or (22 or 33 cells), and (four cells).