atcoder#ABC136E. [ABC136E] Max GCD
[ABC136E] Max GCD
Score : points
Problem Statement
We have a sequence of integers: .
You can perform the following operation between and times (inclusive):
- Choose two integers and such that , each between and (inclusive). Add to and to , possibly producing a negative element.
Compute the maximum possible positive integer that divides every element of after the operations. Here a positive integer divides an integer if and only if there exists an integer such that .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible positive integer that divides every element of after the operations.
2 3
8 20
7
will divide every element of if, for example, we perform the following operation:
- Choose . becomes .
We cannot reach the situation where or greater integer divides every element of .
2 10
3 5
8
Consider performing the following five operations:
- Choose . becomes .
- Choose . becomes .
- Choose . becomes .
- Choose . becomes .
- Choose . becomes .
Then, and , so divides every element of . We cannot reach the situation where or greater integer divides every element of .
4 5
10 1 2 22
7
8 7
1 7 5 6 8 2 6 5
5