atcoder#ARC126C. [ARC126C] Maximize GCD

[ARC126C] Maximize GCD

Score : 600600 points

Problem Statement

Given is a sequence of NN positive integers: A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N). You can do the following operation on this sequence at least zero and at most KK times:

  • choose i{1,2,,N}i\in \{1,2,\ldots,N\} and add 11 to AiA_i.

Find the maximum possible value of gcd(A1,A2,,AN)\gcd(A_1, A_2, \ldots, A_N) after your operations.

Constraints

  • 2N3×1052\leq N\leq 3\times 10^5
  • 1K10181\leq K\leq 10^{18}
  • 1Ai3×1051 \leq A_i\leq 3\times 10^5

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \ldots ANA_N

Output

Print the maximum possible value of gcd(A1,A2,,AN)\gcd(A_1, A_2, \ldots, A_N) after your operations.

3 6
3 4 9
5

One way to achieve gcd(A1,A2,A3)=5\gcd(A_1, A_2, A_3) = 5 is as follows.

  • Do the operation with i=1i = 1 twice, with i=2i = 2 once, and with i=3i = 3 once, for a total of four times, which is not more than K=6K=6.
  • Now we have A1=5A_1 = 5, A2=5A_2 = 5, A3=10A_3 = 10, for which gcd(A1,A2,A3)=5\gcd(A_1, A_2, A_3) = 5.
3 4
30 10 20
10

Doing no operation achieves gcd(A1,A2,A3)=10\gcd(A_1, A_2, A_3) = 10.

5 12345
1 2 3 4 5
2472