atcoder#ABC254F. [ABC254F] Rectangle GCD
[ABC254F] Rectangle GCD
Score : points
Problem Statement
You are given a positive integer and sequences of positive integers each: and .
We have an grid. The square at the -th row from the top and the -th column from the left is called the square . For each pair of integers such that , the square has the integer written on it. Process queries of the following form.
- You are given a quadruple of integers such that . Find the greatest common divisor of the integers contained in the rectangle region whose top-left and bottom-right corners are and , respectively.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Each query is in the following format:
Output
Print lines. The -th line should contain the answer to .
3 5
3 5 2
8 1 3
1 2 2 3
1 3 1 3
1 1 1 1
2 2 2 2
3 3 1 1
2
1
11
6
10
Let denote the integer on the square .
For the -st query, we have , so the answer is their greatest common divisor, which is .
1 1
9
100
1 1 1 1
109