GCD Table
Time limit2sMemory limit512 MB
Given all N^2 pairwise gcd values of a hidden sequence in random order, recover the sequence.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Greedy, Hash map
- Solved
- No attempts yet
Problem
For a sequence of length , the GCD table is defined by
where is the greatest common divisor of and . For example, the GCD table of is
All values of the GCD table are given in arbitrary order. Restore the original sequence .
Input
The first line contains the length of the sequence ().
The second line contains the values of the GCD table in arbitrary order, separated by spaces. Every value is a positive integer no larger than . The input always admits an answer.
Output
Print the elements of the restored sequence on one line, separated by single spaces.
Any ordering of the elements gives the same GCD table, so print them in non-decreasing order. That is the lexicographically smallest answer. The multiset of elements is uniquely determined.