import itertools import sys input = sys.stdin.readline def main(): N = int(input()) *A, = map(int, input().split()) MAX = 10000 cnt = [0]*(MAX+1) for a in A[1:]: cnt[a] += 1 ptr = list(range(MAX+1)) def getnxt(x): while ptr[x] <= MAX and cnt[ptr[x]] == 0: ptr[x] += x return ptr[x] if ptr[x] <= MAX else None def getmin(v): maxv = ans = MAX * MAX for i in itertools.count(1): if i*i > v: return ans if v % i == 0: n = getnxt(i) if n is not None: l = n * (v // i) if maxv > l: maxv = l ans = n elif maxv == l: ans = min(ans, n) n = getnxt(v // i) if n is not None: l = n * i if maxv > l: maxv = l ans = n elif maxv == l: ans = min(ans, n) ans = [A[0]] while len(ans) != N: ret = getmin(ans[-1]) ans.append(ret) cnt[ret] -= 1 print(*ans, sep=' ') if __name__ == '__main__': main()