#abc254f. F - Rectangle GCD
F - Rectangle GCD
Score : points
问题描述
你将获得一个正整数 以及两个各有 个正整数的序列: 和 。
我们有一个 的网格。从上到下第 行、从左到右第 列的方格被称为方格 。对于每一对整数 ,满足 ,方格 上写有整数 。处理 个以下形式的查询请求。
- 给定一组四个整数 ,满足 。找出以 为左上角、 为右下角的矩形区域内的所有整数的最大公约数。
以上为通义千问 qwen-max 翻译,仅供参考。
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 .
Sample Input 1
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
Sample Output 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 .
Sample Input 2
1 1
9
100
1 1 1 1
Sample Output 2
109
update @ 2024/3/10 10:50:11