package main import ( "fmt" ) func divisors(num int) []int { var ret []int for i := 1; i*i < num; i++ { if num%i == 0 { ret = append(ret, i) if i*i != num { ret = append(ret, num/i) } } } return ret } var dp, m [10001]int func main() { var N int fmt.Scan(&N) A := make([]int, N) for i := 0; i < N; i++ { fmt.Scan(&A[i]) m[A[i]]++ } next := A[0] m[next]-- fmt.Print(next) for i := 0; i < N-1; i++ { divisor := divisors(next) check := 99999 ans := 0 for _, d := range divisor { for d*dp[d] <= 10000 { if m[d*dp[d]] > 0 { if check <= dp[d] { break } ans = d * dp[d] check = dp[d] } else { dp[d]++ } } } next = ans m[next]-- fmt.Print(" ", next) } fmt.Print("\n") }