#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#include<map>
using namespace std;
const int maxn=250010;
int ans[510];
int num[maxn];
map<int,int >vis;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
bool cmp(int a,int b){
return a>b;
}
int main()
{
int t,i,j,k,n,m,cnt=0;
scanf("%d",&n);
vis.clear();
for(i=0;i<n*n;++i){
scanf("%d",&num[i]);
vis[num[i]]++;
}
if(n==1){
printf("%d\n",num[0]);
return 0;
}
sort(num,num+n*n,cmp);vis[gcd(num[0],num[1])]-=2;
ans[cnt++]=num[0];ans[cnt++]=num[1];vis[num[0]]--;vis[num[1]]--;
for(i=2;i<n*n;++i){
if(vis[num[i]]!=0){
for(j=0;j<cnt;++j){
vis[gcd(ans[j],num[i])]-=2;
}
ans[cnt++]=num[i];
vis[num[i]]--;
}
}
for(i=0;i<cnt;++i){
if(i)printf(" %d",ans[i]);
else printf("%d",ans[i]);
}
printf("\n");
return 0;
}
cf583C. GCD Table
最新推荐文章于 2021-06-16 18:11:46 发布