Codeforces Round #323 (Div. 2) C. GCD Table

Source: Internet
Author: User
Tags gcd greatest common divisor

C. GCD Table

The GCD table G of size n x n for an array of positive integers a of lengt H n is defined by formula

Let us remind your that the greatest common divisor (GCD) of the positive integers x and y is the greatest integer which is divisor of both xand y, it is denoted as. For example, for array a = {4, 3, 6, 2} of length 4 the GCD tablewould look as follows: /c12>

Given all the numbers of the GCD table G, restore array a.

Input

The first line contains number n (1≤ n ≤500)-the length of array a. The second line contains n2 space-separated numbers-the elements of the GCD table of g for array a.

All the numbers in the table is positive integers, not exceeding 9. Note that the elements is given in an arbitrary order. It is guaranteed, the set of the input data corresponds to some array a.

Output

In the single line print n positive integers-the elements of array a. If There is multiple possible solutions, you is allowed to print any of them.

Examplesinput
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
Input
2
1 1 1 1
Output


One eye on the appearance of the odd number of times must be the answer, and then yy a bit, feel that there are more than two times even several times the answer, five minutes out of this problem, the result is fst (the person intentions sinister, well actually I was too weak).
Positive solution should be clearly known the largest number must be in the answer, each time the number of the introduction of the answer will be and the previous answer to some of the number of two new GCD values, the original array of the two values, to the end will leave the answer.
#include <iostream>#include<cstdio>#include<queue>#include<map>#include<algorithm>using namespacestd;#defineMAXN 620intA[MAXN *Maxn];map<int,int>MP;intMain () {intN;  while(~SCANF ("%d", &N)) { for(inti =1; I <= n * n; i++) {scanf ("%d", &A[i]); Mp[a[i]]++; } sort (A+1, A +1+ N *N); intCNT =0; intANS[MAXN];  for(inti = n * n; I >=1; i--) {            if(!mp[a[i]])Continue; Mp[a[i]]--;  for(intj =1; J <= CNT; J + +) {MP[__GCD (A[i], ans[j])]-=2; } ans[++CNT] =A[i]; }         for(inti =1; I <= CNT; i++) printf ("%d", Ans[i]); Puts""); }}

Codeforces Round #323 (Div. 2) C. GCD Table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.