#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; vector divisors(int n) { vector res; for (int i = 1; (long long)i*i <= n; ++i) { if (n%i == 0) { res.push_back(i); int j = n / i; if (j != i)res.push_back(j); } } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int N; cin >> N; multiset S[10001]; vi ds[10001]; vi a(N), p(N); rep(i, N) { cin >> a[i]; ds[a[i]] = divisors(a[i]); sort(all(ds[a[i]])); each(d, ds[a[i]])S[d].insert(a[i]); } p[0] = a[0]; rep(i, N - 1) { int b = p[i]; each(d, ds[b]) { auto it = S[d].find(b); S[d].erase(it); } int c = INT_MAX, mi = INT_MAX; each(g, ds[b]) if(sz(S[g])){ int x = *S[g].begin(); int l = b * x / g; if (l < mi || (l == mi && x < c)) { mi = l; c = x; } } p[i + 1] = c; } rep(i, N)cout << p[i] << (i != N - 1 ? ' ' : '\n'); }