package main import ( "fmt" "sort" ) var key int type ByLCM []int func (a ByLCM) Len() int { return len(a) } func (a ByLCM) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByLCM) Less(i, j int) bool { lcmi := lcm(key, a[i]) lcmj := lcm(key, a[j]) if lcmi == lcmj { return a[i] < a[j] } return lcmi < lcmj } func main() { var N int fmt.Scan(&N) a := make(ByLCM, N) for i := 0; i < N; i++ { fmt.Scan(&a[i]) } key = a[0] for i := 1; i < N; i++ { sort.Sort(a[i:]) key = a[i] } ans := fmt.Sprintln(a) fmt.Println(ans[1 : len(ans)-2]) } func lcm(a, b int) int { g := gcd(a, b) return (a / g) * (b / g) * g } func gcd(a, b int) int { if a > b { a, b = b, a } if a == 0 { return b } return gcd(b%a, a) }