题目链接
https://www.luogu.com.cn/problem/P1414
问题分析:
- 题目要求我们求出当挑选出k人时所能得到的最大默契程度。那么我们可以将每个数分解得到的各种因子(包括1和它本身)的数量求出来,然后再对最大默契程度从大到小枚举寻找,当这个因子在给出的一组数中能分解出的数量大于我们要选的人即可。
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int cnt[maxn];
void divide(int n)
{
for (int i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
cnt[i]++;
if (i * i != n)
{
cnt[n / i]++;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
int n;
cin.tie(0);
cout.tie(0);
cin >> n;
int z = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
z = max(z, x);
divide(x);
}
for (int i = 1; i <= n; i++)
{
while (cnt[z] < i)
z--;
cout << z << endl;
}
return 0;
}