#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; #define MAX_PRIME 100000 bool isprime[MAX_PRIME+1]; vector primes; void init_prime(){ fill(isprime, isprime+MAX_PRIME+1, true); isprime[0] = isprime[1] = false; for(int i = 2; i <= MAX_PRIME; i++) { if (isprime[i]) { primes.push_back(i); for(int j = i*2; j <= MAX_PRIME; j += i) isprime[j] = false; } } } int gcd(int a, int b){return (b==0?a:gcd(b,a%b));} int lcm(int a, int b){return a/gcd(a,b)*b;} struct ST { int a, b; }; bool operator<(const ST& a, const ST& b){ if(a.b==b.b) return a.a A; cin >> N; rep(i,N){ cin >> a; A.push_back((ST){a,a}); } rep(i,N){ REP(j,i+1,N){ if(isprime[A[i].a] && isprime[A[j].a]){ A[j].b = A[i].a * A[j].a; }else{ A[j].b = lcm(A[i].a, A[j].a); } } sort(A.begin()+i+1,A.end()); } rep(i,A.size()){ if(i!=0) cout << " "; cout << A[i].a; } cout << endl; return 0; }