#include #include #include #include #include using namespace std; const int MAX_N = 10010; int main() { int N; cin >> N; static int a[MAX_N]; for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a + 1, a + N); static list lst[MAX_N]; for (int i = 0; i < N; i++) { for (int x = 1; x * x <= a[i]; x++) { if (a[i] % x == 0) { lst[x].emplace_back(i); lst[a[i] / x].emplace_back(i); } } } static bool used[MAX_N]; static int ans[MAX_N]; ans[0] = a[0]; used[0] = true; for (int i = 0; i < N; i++) { // a[i]の計算 if (i > 0) { int idx = -1; int lcm = -1; for (int x = 1; x * x <= ans[i - 1]; x++) { int y = ans[i - 1] / x; auto update = [&](int n) { while (!lst[n].empty() and used[lst[n].front()]) lst[n].pop_front(); if (lst[n].empty()) return; int val = a[lst[n].front()] * ans[i - 1] / n; if (idx < 0 or val < lcm) { idx = lst[n].front(); lcm = val; } }; update(x); update(y); } ans[i] = a[idx]; used[idx] = true; } cout << ans[i] << " "; } cout << endl; return 0; }