C - Maximize GCD
Editorial
/


Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
項からなる正整数列 が与えられます。あなたはこの数列に対して、次の操作を 回以上 回以下行うことができます:
- をひとつ選び、 に を加える。
操作後の としてありうる最大値を求めてください。
制約
入力
入力は以下の形式で標準入力から与えられます。
出力
操作後の としてありうる最大値を出力してください。
入力例 1Copy
Copy
3 6 3 4 9
出力例 1Copy
Copy
5
例えば以下のようにして、 を実現できます。
- に対して 回、 に対して 回、 に対して 回の操作を行う。合計の操作回数は 回で、 以下である。
- 操作の結果、, , となり、 である。
入力例 2Copy
Copy
3 4 30 10 20
出力例 2Copy
Copy
10
操作を一度も行わないことで、 を実現できます。
入力例 3Copy
Copy
5 12345 1 2 3 4 5
出力例 3Copy
Copy
2472
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.
Sample Input 1Copy
Copy
3 6 3 4 9
Sample Output 1Copy
Copy
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 .
Sample Input 2Copy
Copy
3 4 30 10 20
Sample Output 2Copy
Copy
10
Doing no operation achieves .
Sample Input 3Copy
Copy
5 12345 1 2 3 4 5
Sample Output 3Copy
Copy
2472