#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const int MAXN = 10011; int a[MAXN]; set S[MAXN]; vector divs[MAXN]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; for (int j = 1; j*j <= a[i]; j++) { if (a[i]%j == 0) { divs[i].push_back(j); S[j].insert(pii(a[i], i)); if (j*j != a[i]) { divs[i].push_back(a[i]/j); S[a[i]/j].insert(pii(a[i], i)); } } } } int index = 0; for (int i = 0; i < N; i++) { cout << a[index] << " "; pii mini(1<<30, 1<<30); int id = 0; for (int div : divs[index]) { S[div].erase(pii(a[index], index)); if (S[div].empty()) continue; pii p = *S[div].begin(); int tmp = p.first/div * a[index]; pii q(tmp, p.first); if (q < mini) { mini = q; id = p.second; } } index = id; } cout << endl; return 0; }