#include #include #include #include #include using namespace std; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) void rc(int v,int mn,int mx){if(v divis_list(unsigned int num){ vector divis_list; int rt = int(sqrt((double)num)); for(int i = 1; i <= rt; i++){ if(num % i == 0){ divis_list.push_back(i); if(num / i != i) divis_list.push_back(num / i); } } return divis_list; } const int MAX = 10000; int N, a[MAX+1]; vector divs[MAX+1]; struct comp{ bool operator()(int i, int j){ return (a[i]!=a[j]) ? a[i] divsgrp[MAX+1]; int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N; rc(N,1,10000); REP(i,N){ cin >> a[i]; rc(a[i],1,10000); divs[i] = divis_list(a[i]); if(i > 0) for(auto &d : divs[i]) divsgrp[d].insert(i); } vector result; int prev = 0; result.push_back(a[prev]); REP(i,N-1){ int minval = 0, minidx = -1; for(auto &d : divs[prev]){ if(divsgrp[d].empty()) continue; auto j = *divsgrp[d].begin(); int cm = a[j] / d; if(minidx < 0 || minval > cm || (minval == cm && a[minidx] > a[j])){ minval = cm, minidx = j; } } prev = minidx; result.push_back(a[prev]); for(auto &d : divs[prev]) divsgrp[d].erase(prev); } REP(i,N) cout << result[i] << (i==N-1?"\n":" "); return 0; }