#P3579. [POI 2014] PAN-Solar Panels

[POI 2014] PAN-Solar Panels

Description

For nn queries, each query is given four integers a,b,c,da, b, c, d. Choose any two integers xx and yy from the intervals [a,b][a, b] and [c,d][c, d], respectively, and find the maximum possible value of gcd(x,y)\gcd(x, y).

Input Format

The first line contains an integer nn representing the number of queries.
The next nn lines each contain a query: four integers a,b,c,da, b, c, d specifying the two intervals.

Output Format

Output nn lines, each containing a single integer: the maximum possible value of gcd(x,y)\gcd(x, y) when choosing xx from [a,b][a, b] and yy from [c,d][c, d].

4
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24

8
7
2
5

Hint

Constraints

For 100%100\% of the testdata, 1n10001 \le n \le 1000, 1ab1091 \le a \le b \le 10^9, 1cd1091 \le c \le d \le 10^9.

Notes

Translated by @一只书虫仔。

Translated by ChatGPT 5