#include using namespace std; #define rep(i,n) for (int i = 0; i < n; ++i) using ll = long long; using P = pair; multiset A[100001]; int main() { int N;cin>>N; vectora(N); rep(i,N)cin>>a[i]; rep(i,N){ int ai=a[i]; for (int j = 1; j*j <= ai; j++){ if(ai%j==0){ A[j].insert(ai/j); if(j*j==ai)continue; A[ai/j].insert(j); } } } vector ans; ans.push_back(a[0]); rep(i,N-1){ int ai=ans[i]; int mini=1e9, next; int j=1; for (; j*j <= ai; j++){ if(ai%j==0){ A[j].extract(ai/j); if(!A[j].empty()){ if(mini>*A[j].begin()){ mini=*A[j].begin(); next=mini*j; } } } } if(j*j==ai)j--; for (; j*j >= 1; j--){ if(ai%j==0){ int bi=ai/j; A[bi].extract(j); if(!A[bi].empty()){ if(mini>*A[bi].begin()){ mini=*A[bi].begin(); next=mini*bi; } } } } ans.push_back(next); } rep(i,N)cout<