#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = (ll)(1e+9) + 7; const ll INF = (ll)1000000007 * 1000000007; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LP; typedef pair LDP; const int key = 10000; vector d[key+1]; vector

v[key+1]; queue

q[key + 1]; int n, a[key+1]; void init() { rep1(i, key) { for (int j = i; j <= key; j += i) { d[j].push_back(i); } } } bool used[key + 1]; vector ans; int main(){ init(); cin >> n; rep(i, n) { cin >> a[i]; rep(j, (int)d[a[i]].size()) { int t = d[a[i]][j]; v[t].push_back({ a[i]/t,i }); } } rep1(i, key) { sort(v[i].begin(), v[i].end()); rep(j, (int)v[i].size()) { q[i].push(v[i][j]); } } used[0] = true; int m = a[0]; ans.push_back(a[0]); rep(i, n - 1) { int ma = 2 * key; int nextid = -1; rep(j, d[m].size()) { int dd = d[m][j]; while (!q[dd].empty() && used[q[dd].front().second])q[dd].pop(); if (q[dd].empty())continue; if (ma > q[dd].front().first) { ma = q[dd].front().first; nextid = q[dd].front().second; } } ans.push_back(a[nextid]); m = a[nextid]; used[nextid] = true; } rep(i, (int)ans.size()) { if (i > 0) { cout << " "; } cout << ans[i]; } cout << endl; return 0; }