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. java递归树形菜单显示

    今天写权限整好涉及到一些菜单的显示,最先想到的是递归遍历输出,但是呢在网上找了很多有关的资料没有符合自己需求的所以就自己写了一个,如果觉得靠谱 请点点关注!!!赞一个 首先看一些设计的数据库设计 菜单 ...

  2. iOS中使用block进行网络请求回调

    iOS中使用block进行网络请求回调 HttpRequest.h // // HttpRequest.h // UseBlockCallBack // // Created by Michael o ...

  3. asp.net mvc core 管道以及拦截器初了解

    今天来看一下asp.net core的执行管道.先看下官方说明: 从上图可以抛光,asp.net core的执行顺序是,当收到一个请求后,request请求会先经过已注册的中间件,然后会进入到mvc的 ...

  4. 【小程序】---- input获得焦点时placeholder重影BUG

    问题小程序的input组件有个自身的bug,即当输入框获取焦点时placeholder内容会出现重影现象. 解决思路原理:将placeholder内容单独写在另外的标签里,控制其显示隐藏.操作:将代表 ...

  5. JVM05——JVM类加载机制知多少

    我们已经讲过 JVM 相关的很多常见知识点,感兴趣的朋友可以在我的往期文章中查看.接下来将继续为各位带来 JVM 类加载机制.关注我的公众号「Java面典」了解更多 Java 相关知识点. 类生命周期 ...

  6. JAVA设计模式之-模板方法+(钩子函数)

    1.定义 允许子类对父类的一个或多个步骤进行重写.例如聚合支付场景中有很多共同的步骤,比如验签.四要素验证.风控等等,但是在支付的时候走不同的渠道可能在调用和参数上有很大的不同,比如有的是xml,有的 ...

  7. Nginx配置Web项目(多页面应用,单页面应用)

    目前前端项目 可分两种: 多页面应用,单页面应用. 单页面应用 入口是一个html文件,页面路由由js控制,动态往html页面插入DOM. 多页面应用 是由多个html文件组成,浏览器访问的是对应服务 ...

  8. linux下怎么找到某些命令出自于哪个包

    我们经常会遇到新装机器或者用别人的linux机器的时候找不到某个命令出自哪个软件包而不知道如何安装的情况,用如下命令可以解决 yum provides TARGET 举例说明: #要找到lsb-rel ...

  9. linux入门系列18--Web服务之Apache服务2

    接上一篇文章,在了解Apache基本配置以及SELinux相关知识后,继续演示Apache提供的虚拟主机功能以及访问控制方式. 如果还没看上一篇的建议先查看后再来,上篇文章"linux入门系 ...

  10. springboot基础-redis集群

    一.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...