import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Scanner sc = new Scanner(System.in); HashMap> divisors = new HashMap(); HashMap> target = new HashMap(); int n = sc.nextInt(); int[] a = new int[n]; ArrayList out = new ArrayList(); //1個目は固定 out.add(sc.nextInt()); for (int i = 1; i < n; i++) { int tmp = sc.nextInt(); ArrayList tmpPrimes = getPrime(tmp); divisors.put(tmp, tmpPrimes); for (int prime : tmpPrimes) { TreeMap tmpTarget; if (target.containsKey(prime)) { tmpTarget = target.get(prime); } else { tmpTarget = new TreeMap(); target.put(prime, tmpTarget); } if (tmpTarget.containsKey(tmp)) { int count = tmpTarget.get(tmp) + 1; tmpTarget.replace(tmp, count); } else { tmpTarget.put(tmp, 1); } } } ArrayList exe = getPrime(out.get(0)); for (int i = 1; i < n; i++) { int min = Integer.MAX_VALUE; int lcm = Integer.MAX_VALUE; for (int tmpNum : exe) { TreeMap tmpMap = target.get(tmpNum); if (tmpMap == null || tmpMap.isEmpty()) { continue; } int tmpMin = tmpMap.keySet().iterator().next(); int tmpLcm = getLcm(tmpMin, out.get(i - 1)); if (lcm > tmpLcm || (lcm == tmpLcm && min > tmpMin)) { lcm = tmpLcm; min = tmpMin; } } exe = divisors.get(min); for (int j : exe) { TreeMap tmpTree = target.get(j); int count = tmpTree.get(min); if (count == 1) { tmpTree.remove(min); } else { count--; tmpTree.replace(min, count); } } out.add(min); } System.out.print(out.get(0)); for (int i = 1; i < out.size(); i++) { System.out.print(" " + out.get(i)); } System.out.println(); } private static ArrayList getPrime(int source) { ArrayList ret = new ArrayList(); int max = source / 2; for (int i = 1; i <= max; i++) { if (source % i == 0) { ret.add(i); } } ret.add(source); return ret; } private static int getLcm(int a, int b) { int tmpA = a; int tmpB = b; while (tmpA != tmpB) { if (tmpA > tmpB) { tmpA = tmpA - tmpB; } else { tmpB = tmpB - tmpA; } } return a * b / tmpA; } }