Files
lanqiao/15lanqiao/test5.cpp
2025-03-19 14:21:28 +08:00

46 lines
954 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// lanqiao 19711 宝石组合
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
vector<int> fac[N], s[N];
int main() {
for(int i = 1; i <= 1e5; i++){
for(int j = i; j <= 1e5; j += i){
fac[j].push_back(i);
}
}
int n; cin>>n;
for(int i = 1; i<=n; i++) cin >> a[i];
// 保证字典序最小
sort(a+1, a+1+n);
for(int i = 1; i <=n; i++){
for(int j = 0; j < fac[a[i]].size(); j++){
s[fac[a[i]][j]].push_back(a[i]);
}
}
for(int i = 1e5; i>=0; i--){
if(s[i].size() >= 3){
cout << s[i][0] << " " << s[i][1] << " " << s[i][2] << endl;
break;
}
}
return 0;
}
/* test samples
5
1 2 3 4 9
*/
/*
排序后的宝石为 [1, 2, 3, 4, 9]。
因数数组 fac 和宝石数组 s 的关系如下:
s[1] 包含所有宝石 [1, 2, 3, 4, 9]。
s[2] 包含 [2, 4]。
s[3] 包含 [3, 9]。
s[4] 包含 [4]。
s[9] 包含 [9]。
最终s[1] 中有5个宝石满足条件。
输出前三个宝石1 2 3。
*/