'commit'
This commit is contained in:
41
TangDou/LuoGuBook/P1414.cpp
Normal file
41
TangDou/LuoGuBook/P1414.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e6 + 10;
|
||||
int n; //n个同学的能力值
|
||||
int m; //当前情况下可能的最大公约数
|
||||
int c[N]; //每个约数i出现的次数c[i]
|
||||
|
||||
/**
|
||||
* 功能:获取指定数x的所有约数
|
||||
* @param x
|
||||
*/
|
||||
void ys(int x) {
|
||||
for (int i = 1; i <= sqrt(x); i++)
|
||||
//有约数
|
||||
if (x % i == 0) {
|
||||
c[i]++; //i作为约数的次数++
|
||||
//记录另一个相对的约数
|
||||
//x!=i*i 防止记录重复,如果是完全平方,就记一个,这个是大的
|
||||
if (x != i * i) c[x / i]++;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
//读入n个能力值
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x;
|
||||
cin >> x;
|
||||
m = max(m, x); //记录目前最大能力值
|
||||
//找出所有约数
|
||||
ys(x);
|
||||
}
|
||||
|
||||
//在n个数中选择i个数字,求可能产生的最大公约数。
|
||||
for (int i = 1; i <= n; i++) {
|
||||
while (c[m] < i) m--;
|
||||
cout << m << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user