#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heapify, heappop from collections import defaultdict N, *A = map(int, read().split()) class RemovableHeap(): def __init__(self, data): self.n_elem = len(data) self.data = data heapify(self.data) self.counter = defaultdict(int) for x in data: self.counter[x] += 1 def top(self): while True: x = self.data[0] if not self.counter[x]: heappop(self.data) continue return x def push(self, x): self.counter[x] += 1 heappush(self.data, x) self.n_elem += 1 def pop(self): while True: x = heappop(self.data) if self.counter[x]: self.counter[x] -= 1 self.n_elem -= 1 return x def remove(self, x): self.counter[x] -= 1 self.n_elem -= 1 def empty(self): return self.n_elem == 0 U = 10 ** 4 div = [[] for _ in range(U + 1)] for d in range(1, U + 1): for i in range(d, U + 1, d): div[i].append(d) INF = 10 ** 9 multiples = [[INF] for _ in range(U + 1)] for x in A[1:]: for d in div[x]: multiples[d].append(x) for i in range(1, U + 1): multiples[i] = RemovableHeap(multiples[i]) answer = [A[0]] n = A[0] for _ in range(N - 1): best_lcm = INF best_x = 0 for d in div[n]: x = multiples[d].top() lcm = n * x // d if best_lcm > lcm: best_lcm = lcm best_x = x n = best_x answer.append(n) for d in div[n]: multiples[d].remove(n) print(*answer) # %% # import numpy as np # from numba import njit # %%