D. Recover it!

Authors guessed an array aa consisting of nn integers; each integer is

not less than 22 and not greater than 2⋅1052⋅105. You don’t know the

array aa, but you know the array bb which is formed from it with the

following sequence of operations:

Firstly, let the array bb be equal to the array aa; Secondly, for each

ii from 11 to nn: if aiai is a prime number, then one integer paipai

is appended to array bb, where pp is an infinite sequence of prime

numbers (2,3,5,…2,3,5,…); otherwise (if aiai is not a prime number),

the greatest divisor of aiai which is not equal to aiai is appended to

bb; Then the obtained array of length 2n2n is shuffled and given to

you in the input. Here paipai means the aiai-th prime number. The

first prime p1=2p1=2, the second one is p2=3p2=3, and so on.

Your task is to recover any suitable array aa that forms the given

array bb. It is guaranteed that the answer exists (so the array bb is

obtained from some suitable array aa). If there are multiple answers,

you can print any.

Input

The first line of the input contains one integer nn

(1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa.

The second line of the input contains 2n2n integers

b1,b2,…,b2nb1,b2,…,b2n (2≤bi≤27501312≤bi≤2750131), where bibi is the

ii-th element of bb. 27501312750131 is the 199999199999-th prime

number.

Output

In the only line of the output print nn integers a1,a2,…,ana1,a2,…,an

(2≤ai≤2⋅1052≤ai≤2⋅105) in any order — the array aa from which the

array bb can be obtained using the sequence of moves given in the

problem statement. If there are multiple answers, you can print any.

Examples

input

Copy

3
3 5 2 3 2 4
output Copy 3 4 2
input Copy 1
2750131 199999
output Copy 199999
input Copy 1
3 6
output Copy 6

题解如下

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int Len = 1e6;
int prime[Len * 3];
int ar[Len * 3];
int br[3 * Len];
int barrel[3 * Len];
vector<int> vec;
int n; bool cmp(int a,int b)
{
return a > b;
}
void Prime()
{
for(int i = 2; i <= Len * 3; i ++)
prime[i] = 1;
//素数筛选法
for(int i = 2; i * i <= Len * 3; i ++)
{
if(prime[i])
{
for(int j = i * i; j <= Len * 3; j += i)
prime[j] = 0;
}
}
} void init()
{
Prime(); int pos = 1;
for(int i = 2; i <= Len * 3; i ++)
{
if(prime[i])
{
ar[pos ++] = i;
}
}
//输入
for(int i = 1; i <= 2 * n; i ++)
{
scanf("%d",&br[i]);
}
//统计各个数字出现的次数
for(int i = 1; i <= 2 * n; i ++)
{
barrel[br[i]] ++;
}
sort(br + 1 , br + 2 * n + 1 , cmp);
}
void Solve()
{
init(); for(int i = 1; i <= 2 * n; i ++)
{
int cnt = barrel[br[i]];
if(cnt > 0)
{
if(! prime[br[i]])
{
int mx_divisor;
for(int j = 2; ; j ++)
if(br[i] % j == 0)
{
mx_divisor = br[i] / j;
break;
} if(barrel[mx_divisor] > 0)
{
barrel[mx_divisor] --;
vec.push_back(br[i]);
barrel[br[i]] --;
}
}
else
{
int pri = ar[br[i]];
if(barrel[pri] > 0)
{
barrel[pri] --;
vec.push_back(br[i]);
barrel[br[i]] --;
}
}
}
} for(auto x : vec)
printf("%d ",x);
} int main()
{
//freopen("test.txt","r",stdin);
scanf("%d",&n);
Solve(); return 0;
}

Codeforces Round #565 (Div. 3)--D. Recover it!--思维+欧拉筛的更多相关文章

  1. Codeforces Round #565 (Div. 3) C. Lose it! (思维)

    题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...

  2. Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路

    D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...

  3. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...

  4. Codeforces Round #565 (Div. 3) B. Merge it!

    链接: https://codeforces.com/contest/1176/problem/B 题意: You are given an array a consisting of n integ ...

  5. Codeforces Round #565 (Div. 3) A. Divide it!

    链接: https://codeforces.com/contest/1176/problem/A 题意: You are given an integer n. You can perform an ...

  6. Codeforces Round #565 (Div. 3) C. Lose it!

    链接: https://codeforces.com/contest/1176/problem/C 题意: You are given an array a consisting of n integ ...

  7. Codeforces Round #565 (Div. 3) B

    B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...

  8. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  9. Codeforces Round #565 (Div. 3) F.Destroy it!

    题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...

随机推荐

  1. nes 红白机模拟器 第7篇 编译使用方法

    模拟器,基于 InfoNES ,作者添加修改以下功能: 1, joypad 真实手柄驱动程序(字符型设备驱动) 2,原始图像只有256*240 ,添加 图像放大算法,这里实现了2种,a, 最近邻插值 ...

  2. 实验二 Samba服务器配置

    实验二 实 验 基 本 信 息 实验名称:Samba服务器配置 实验时间:    年 月 日 实验地点: 实验目的: 了解Samba环境及协议 掌握Samba的工作原理 掌握主配置文件Samba.co ...

  3. 全球疫情统计APP图表形式展示

    全球疫情统计APP图表展示: 将该任务分解成三部分来逐个实现: ①爬取全球的疫情数据存储到云服务器的MySQL上 ②在web项目里添加一个servlet,通过参数的传递得到对应的json数据 ③设计A ...

  4. 【2020-03-21】Dubbo本地环境搭建-实现服务注册和消费

    前言 本周主题:加班工作.本周内忙于CRUD不能自拔,基本每天都是九点半下班,下周上线,明天还要加班推进进度.今天是休息日,于是重拾起了dubbo,打算近期深入了解一下其使用和原理.之所以说是重拾,是 ...

  5. Lambda表达式学习笔记

    Lambda基础语法 Java8中引入了一个新的操作符" -> ",该操作符被称为箭头操作符或Lambda操作符,箭头操作符将Lambda表达式拆分成两部分: 左侧:Lamb ...

  6. Sqli-labs 搭建SQL注入平台

    sqli-labs是一款学习sql注入的开源平台,共有75种不同类型的注入. 搭建步骤: 1.在Windows系统中安装WAMP 下载地址:https://pan.baidu.com/s/1HY0hF ...

  7. 14. LiveBos编号自动生成

    (1) var temp="Apex"; var no=""+ABS_DYNSERIALNO(true,temp); var len=no.length; va ...

  8. 云CRM和本地CRM哪个更好

    现在CRM系统按照服务器部署方式的不同分为本地CRM和云CRM两种,本地CRM需要在企业内部部署服务器,而云CRM的服务器则是安装在云服务器上面,很多企业可能不知道应该选择云CRM还是本地CRM.下面 ...

  9. LeetCode--179场周赛题解

    水题: class Solution { public: string generateTheString(int n) { string s; string a="a",b=&q ...

  10. 【面试必备】用了那么多次 ping,是时候知道 ping 是如何工作的了!

    每日一句英语学习,每天进步一点点: 前言 在日常生活或工作中,我们在判断与对方网络是否畅通,使用的最多的莫过于 ping 命令了. “那你知道 ping 是如何工作的吗?” —— 来自小林的灵魂拷问 ...