import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys from collections import Counter, deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines def Divisors(N): divisors=[] for i in range(1,N+1): if i**2>=N: break elif N%i==0: divisors.append(i) if i**2==N: divisors+=[i]+[N//i for i in divisors[::-1]] else: divisors+=[N//i for i in divisors[::-1]] return divisors def LCM(n,m): if n or m: return abs(n)*abs(m)//math.gcd(n,m) return 0 N=int(readline()) A=list(map(int,readline().split())) dct=defaultdict(list) for i,a in enumerate(A): for d in Divisors(a): dct[d].append((a,i)) for d in dct.keys(): heapify(dct[d]) used=[False]*N ans_lst=[0] used[0]=True a=A[0] for _ in range(N-1): m=(float('inf'),) m_i=None for d in Divisors(a): if not dct[d]: continue aa,i=dct[d][0] while used[i]: heappop(dct[d]) if not dct[d]: break aa,i=dct[d][0] else: if m>(LCM(a,aa),aa): m=(LCM(a,aa),aa) m_i=i ans_lst.append(m_i) used[m_i]=True a=A[m_i] ans_lst=[A[i] for i in ans_lst] print(*ans_lst)