我真傻,真的。这么简单的题都想了半天
其实挺简单的。暴力记录每一个约数出现的个数。
然后考虑输出答案。
可以想到,答案是逐渐变小的,而每个约数出现次数随着其增长而减小。
于是可以用一些玄学技巧来找出答案。
#include#include #include #include using namespace std;typedef pair P;const int MAXN = 1e4 + 20;const int MAXM = 1e6 + 20;int N, a[MAXN];int vis[MAXM];inline void calc(int x){ for(int i = 1; i * i <= x; i++){ if(x % i == 0) { ++vis[i]; if(x / i != i) ++vis[x / i]; } }}int main(){ cin>>N; for(int i = 1; i <= N; i++){ scanf("%d", &a[i]); calc(a[i]); } int p = MAXM - 1; for (int i = 1; i <= N; i++) { while (vis[p] < i) p--; cout << p << endl; } return 0;}