#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 2000
int a[MN+5],u[MN+5],mn;
vector<int> v[MN+5],ans[MN+5];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
void dfs(int x)
{
	u[x]=1;if(a[x]<a[mn])mn=x;
	for(int i=0;i<v[x].size();++i)if(!u[v[x][i]])dfs(v[x][i]);
}
bool cmp(int x,int y){return a[x]<a[y];}
void merge(vector<int>&x,vector<int>&y)
{
	vector<int> z;int i=0,j=0;
	while(i<x.size()&&j<y.size())z.push_back(x[i]>y[j]?x[i++]:y[j++]);
	while(i<x.size())z.push_back(x[i++]);
	while(j<y.size())z.push_back(y[j++]);
	x.clear();
	for(int i=0;i<z.size();++i)x.push_back(z[i]);
}
void solve(int x)
{
	u[x]=2;sort(v[x].begin(),v[x].end(),cmp);
	for(int i=0;i<v[x].size();++i)if(u[v[x][i]]<2)
		solve(v[x][i]),merge(ans[x],ans[v[x][i]]);
	ans[x].push_back(0);
	for(int i=ans[x].size();--i;)ans[x][i]=ans[x][i-1];
	ans[x][0]=a[x];
}
int main()
{
	int n=read(),i,j;
	for(i=1;i<=n;++i)a[i]=read();
	for(i=1;i<=n;++i)for(j=1;j<i;++j)if(gcd(a[i],a[j])>1)
		v[i].push_back(j),v[j].push_back(i);
	for(i=1;i<=n;++i)if(!u[i])dfs(mn=i),solve(mn),merge(ans[0],ans[mn]);
	for(i=0;i<ans[0].size();++i)printf("%d ",ans[0][i]);
}