You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
496 B
C++

#include <iostream>
#include <map>
using namespace std;
map<int, int> M;
int main()
{
int n, k;
cin >> n >> k;
for (int i = 0, j, x; i < n; i++)
{
cin >> x;
for (j = 1; j * j < x; j++) if (x % j == 0) M[j]++, M[x / j]++;
if (j * j == x) M[j]++;
}
for (map<int, int>::reverse_iterator rite = M.rbegin(); rite != M.rend(); rite++)
if (rite->second >= k)
{
cout << rite->first;
break;
}
return 0;
}