#include using LL = long long; const int N = 1e6 + 7; int a[N], b[N], nxt[N], n; std::vector p[N]; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); ++b[a[i]]; } int m = *std::max_element(a + 1, a + n + 1); for(int i = 1; i <= m; ++i) for(int j = i; j <= m; j += i) p[j].push_back(i); for(int i = 1; i <= m; ++i) nxt[i] = i; --b[a[1]]; for(int i = 1; i < n; ++i) { if(i != 1 && b[a[i]]) { --b[a[i]]; a[i + 1] = a[i]; continue; } int v = 0; LL w = 1e18; for(int x: p[a[i]]) { while(nxt[x] <= m && !b[nxt[x]]) nxt[x] += x; if(b[nxt[x]]) { LL nw = 1LL * a[i] * nxt[x] / x; if(nw < w || (nw == w && nxt[x] < v)) { v = nxt[x]; w = nw; } } } a[i + 1] = v; --b[v]; } for(int i = 1; i <= n; ++i) printf("%d ", a[i]); putchar(10); return 0; }