// yukicoder: No.14 最小公倍数ソート // 2019.4.30 bal4u #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() // 非負整数の入力 { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } void out(int n, int sp) // 非負整数の表示(出力) { int i; char b[20]; if (sp) pc(' '); if (!n) pc('0'); else { i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } } int N; int a[10005]; int f[10005]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int i, j, k, N; N = in(); for (i = 0; i < N; i++) a[i] = in(), f[a[i]]++; qsort(a+1, N-1, sizeof(int), cmp); out(a[0], 0), f[a[0]]--; i = 1, j = N-1; while (a[i] == 1) out(1, 1), f[1]--, i++, j--; while (j > 0) { while (a[i] == a[i-1]) out(a[i], 1), f[a[i]]--, i++, j--; if (j > 0) { int t = i-1; while (!f[a[i]]) i++; for (k = 2; k < a[i]; k++) { if (f[k*a[t]]) { out(k*a[t], 1), f[k*a[t]]--, j--; break; } } if (k == a[i]) out(a[i], 1), f[a[i]]--, i++, j--; } } pc('\n'); return 0; }