Under construction

Still being built. Things may change

GCD

Time limit4sMemory limit512 MB

Summary
Given an array of up to 1e5 integers up to 1e18, erase at most k elements to maximize the GCD of the remaining elements.
Level

Medium7 of 10

Topics
Number theory, Math, Probability
Solved
No attempts yet

Problem

You are given an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n. Find the maximum possible greatest common divisor of all numbers in the array if you can erase no more than kk elements (k≤n2k \le \frac{n}{2}) from it.

Input

The first line contains two integers nn, the number of elements in the array, and kk, the maximum number of elements you can erase (2≤n≤1052 \le n \le 10^5, 0≤k≤n20 \le k \le \frac{n}{2}). The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, the array aa (1≤ai≤10181 \le a_i \le 10^{18}).

Output

Print the maximum possible greatest common divisor of all elements left in the array after erasing no more than kk elements.

Examples3

  1. Example 1

    Input
    4 1
    6 15 35 14
    
    Expected output
    1
    
  2. Example 2

    Input
    4 2
    6 15 35 14
    
    Expected output
    7
    
  3. Example 3

    Input
    3 1
    897612484786617600 5828 16027
    
    Expected output
    1457