裴蜀定理的扩展
最后返回的一定是\(k\)个数的\(gcd\)
因此对于每个数暴力分解因子统计即可
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
int n, k, ans;
map <int, int> ex;
inline void resolve() {
int v; cin >> v;
for(int i = 1; i * i <= v; i ++)
if(v % i == 0) {
ex[i] ++;
if(ex[i] >= k && i >= ans) ans = i;
if(i != v / i) ex[v / i] ++;
if(ex[v / i] >= k && v / i >= ans) ans = v / i;
}
}
int main() {
cin >> n >> k;
for(int i = 1; i <= n; i ++) resolve();
printf("%d\n", ans);
return 0;
}