atcoder#ARC126C. [ARC126C] Maximize GCD
[ARC126C] Maximize GCD
Score : points
Problem Statement
Given is a sequence of positive integers: . You can do the following operation on this sequence at least zero and at most times:
- choose and add to .
Find the maximum possible value of after your operations.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible value of after your operations.
3 6
3 4 9
5
One way to achieve is as follows.
- Do the operation with twice, with once, and with once, for a total of four times, which is not more than .
- Now we have , , , for which .
3 4
30 10 20
10
Doing no operation achieves .
5 12345
1 2 3 4 5
2472