#P4571. Optimal Fuel Exchange

    ID: 17817 Type: Default 1000ms 256MiB

Optimal Fuel Exchange

Optimal Fuel Exchange

jyy is eager to return to Earth but his spaceship lacks sufficient fuel. One day, he negotiates with the Martians who agree to give him some fuel in exchange for K bottles selected from his spaceship's N bottles. Each bottle has no gradation, but its capacity is marked at the bottle’s opening. The capacity of the i-th bottle is given by \(V_i\) where \(1 \le V_i \le 10^9\). After receiving the K bottles, the Martians perform operations in their fuel depot to extract a little fuel. They will only use the following 3 operations:

  1. Fill a bottle completely with fuel.
  2. Empty a bottle completely back into the fuel depot.
  3. Pour fuel from bottle \(a\) to bottle \(b\) until bottle \(b\) is full or bottle \(a\) is empty (fuel loss is negligible during pouring).

It is known that using these operations, the smallest positive fuel volume that can be measured is exactly the greatest common divisor (GCD) of the capacities of the bottles used. Therefore, the fuel amount the Martians provide will be \(\gcd(V_{i_1}, V_{i_2}, \dots, V_{i_K})\), where \(i_1, i_2, \dots, i_K\) are the indices of the chosen bottles.

jyy wants to maximize the fuel he receives by selecting the optimal set of K bottles. Your task is to compute the maximum possible fuel volume (i.e. maximum possible GCD) that can be obtained from some choice of K bottles.

inputFormat

The first line contains two integers \(N\) and \(K\) (\(1 \le K \le N \le 1000\)). The second line contains \(N\) integers \(V_1, V_2, \dots, V_N\) (\(1 \le V_i \le 10^9\)), which represent the capacities of the bottles.

outputFormat

Output a single integer: the maximum fuel volume that can be obtained, i.e. the maximum possible GCD among any selection of K bottles.

sample

3 2
6 10 15
5