1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n; vector<int> v, ans; map<int, int> m; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n * n; i++) { int x; cin >> x; v.push_back(x); m[x]++; } sort(v.begin(), v.end()); for (int i = v.size() - 1; i >= 0; i--) { if (!m[v[i]]) continue; ans.push_back(v[i]); m[v[i]]--; for (int j = 0; j < ans.size() - 1; j++) m[gcd(v[i], ans[j])] -= 2; } for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; return 0; }
- 1
信息
- ID
- 1266
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者