题意 如果一个数是质数 他只能生成质数序列的第他本身个质数 否则会生成他的最大因子
首先我们要知道 肯定是把两个质数分开 然后我们发现 只有大的质数会被小的质数生成 比如 3 是 2 生成的 5 是 3 生成的 那么我们从大到小 找到一个质数就把生成他的质数放在答案序列里面 如果不是质数 那么我们就需要把他放进答案序列里面 消除他最大因子的贡献
一开始忘记 n是 2n re了一发
ans[0]和ans[2]是想要的答案
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
int arr[400025];
const int MAX_N = 2751150;
int prime[MAX_N];
int flag[MAX_N+5];
int tot,num[MAX_N];
map<int,int > mp;
void make_prime()
{
for(int i = 2;i<=MAX_N;++i)
{
if(!flag[i])
{
prime[++tot] = i;
mp[i] = tot;
for(int j = i + i;j<=MAX_N;j+=i)
flag[j] = 1;
}
}
}
vector<int > ans[4];
bool cmp(int a,int b)
{
return a > b;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
make_prime();
scanf("%d",&n);
for(int i = 1;i<=2*n;++i)
{
scanf("%d",&arr[i]);
num[arr[i]]++;
}
int cnt = 0;
sort(arr+1,arr+1+2*n,cmp);
for(int i = 1;i<=2*n;++i)
{
if(num[arr[i]])
{
if(!flag[arr[i]])
{
if(num[mp[arr[i]]])
{
num[arr[i]]-- ;
num[mp[arr[i]]]--;
ans[0].push_back(arr[i]);
ans[1].push_back(mp[arr[i]]);
}
else
{
cnt++;
num[arr[i]]--;
ans[2].push_back(arr[i]);
}
}
else
{
cnt++;
num[arr[i]]--;
ans[2].push_back(arr[i]);
for(int j = 2;j*j<=arr[i];++j)
{
if(arr[i]%j==0)
{
num[arr[i]/j]--;
ans[3].push_back(arr[i]/j);
break;
}
}
}
}
}
if(ans[1].size())
{
for(int i = 0;i<ans[1].size();++i)
printf("%d ",ans[1][i]);
}
// for(int i = 0;i<cnt;++i)
// dbg2(i,ans[2][i]);
// dbg(cnt);
if(cnt)
{
for(int i = 0;i<cnt;++i)
printf("%d ",ans[2][i]);
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}