CF-1176D Posted on 2019-06-12 | In cf | Views: 题意 题解排序, 从大到小处理, 若当前最大的为素数, 那它一定是 $b$, 若当前最大数为合数, 那它一定是 $a$ 代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#include <bits/stdc++.h>using namespace std;#define forl(i, l, r) for (int i = l; i <= r; i++)#define forr(i, r, l) for (int i = r; i >= l; i--)#define for1(i, n) for (int i = 1; i <= n; i++)#define fro1(i, n) for (int i = 1; i <= n; i++)#define for0(i, n) for (int i = 0; i < n; i++)#define fro0(i, n) for (int i = 0; i < n; i++)#define meminf(a) memset(a, inf, sizeof(a))#define mem_1(a) memset(a, -1, sizeof(a))#define mem0(a) memset(a, 0, sizeof(a))#define memcp(a,b) memcpy(a,b,sizeof(b))#define oper(type) bool operator <(const type y)const#define mp make_pair#define pu_b push_back#define pu_f push_front#define po_b pop_back#define po_f pop_front#define fi first#define se second#define whiel while#define retrun returntypedef pair<long long, long long> pll;typedef vector<long long> vll;typedef pair<int, int> pii;typedef unsigned long long ull;typedef vector<int> vii;typedef long double db;typedef long long ll;typedef int itn;int in(int &a,int &b,int &c,int &d){return scanf("%d%d%d%d",&a,&b,&c,&d);}int in(int &a,int &b,int &c){return scanf("%d%d%d",&a,&b,&c);}int in(int &a,int &b){return scanf("%d%d",&a,&b);}int in(ll &a){return scanf("%lld",&a);}int in(int &a){return scanf("%d",&a);}int in(char *s){return scanf("%s",s);}int in(char &s){return scanf("%c",&s);}int in(db &a){return scanf("%Lf",&a);}void out(int a){printf("%d ",a);}void outln(int a){printf("%d\n",a);}void out(ll a){printf("%lld ",a);}void outln(ll a){printf("%lld\n",a);}const db pi = acos((db)-1);const ll inf =0x3f3f3f3f;const db eps = 1e-8;const int N = 3e6;const ll mod = 1e9+7;int sign(db a) { return a < -eps ? -1 : a > eps;}int db_cmp(db a, db b){ return sign(a-b); }int Div[N];int prime[N],num_prime=0;void get_prime(){ for(int i=2;i<N;i++){ if(!Div[i]) { prime[num_prime++]=i; Div[i]=-num_prime; } for(int j=0;j<num_prime&&(ll)i*prime[j]<N;j++){ int k = i*prime[j]; Div[k] = i; if(i % prime[j] == 0) break; } }}itn n,a[400005],cnt[N];int main() { get_prime(); in(n); for0(i,2*n){ in(a[i]); cnt[a[i]]++; } sort(a,a+2*n); for(int i=2*n-1;i>=0;i--){ if(cnt[a[i]]){ if(Div[a[i]]>0){ out(a[i]); cnt[a[i]]--; cnt[Div[a[i]]]--; }else{ int tmp=-Div[a[i]]; out(tmp); cnt[tmp]--; cnt[a[i]]--; } } } return 0;}