Author: lllyouo
Date: 20250702
tag: 约数、最大公约数
link: https://www.luogu.com.cn/problem/P1414问题描述
分析
当
可知:
本题中可使用数组 cnt[i] 记录数字
当求
参考代码
cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, cnt[N];
int main() {
cin >> n;
int maxv = 0;
for (int i = 0; i < n; i++) {
int x; cin >> x;
maxv = max(maxv, x);
for (int j = 1; j * j <= x; j++) {
if (x % j == 0) {
cnt[j]++;
if (j != x / j) cnt[x / j]++;
}
}
}
int ans = maxv;
for (int i = 1; i <= n; i++) {
while (cnt[ans] < i) ans--;
cout << ans << endl;
}
return 0;
}