Skip to content

Instantly share code, notes, and snippets.

@ctylim
Last active October 4, 2015 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctylim/5449bdc4f0263f7c6800 to your computer and use it in GitHub Desktop.
Save ctylim/5449bdc4f0263f7c6800 to your computer and use it in GitHub Desktop.
Codeforces #323 div2C
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
};
template <typename T>
void output(T a, int precision) {
if(precision > 0){
cout << setprecision(precision) << a << "\n";
}
else{
cout << a << "\n";
}
}
int gcd(int a, int b){
if (a > b) {
swap(a, b);
}
if (b % a == 0) {
return a;
}
else{
return gcd(b % a, a);
}
}
int main() {
// source code
multiset<int> ms;
int N = inputValue(); // 500
vector<int> A(N * N);
vector<int> check(N * N);
rep(i, N * N){
A[i] = inputValue();
}
rep(i, N * N){
ms.insert(A[i]);
}
vector<int> ret;
rep(i, N){
int m = *(ms.rbegin());
ms.erase(ms.find(m));
rep(j, ret.size()){
ms.erase(ms.find(gcd(m, ret[j])));
ms.erase(ms.find(gcd(m, ret[j])));
}
ret.push_back(m);
}
rep(i, N){
cout << ret[i] << " ";
}
output("", 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment