CF1176D.Recover it!

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Authors guessed an array aa consisting of nn integers; each integer is not less than 22 and not greater than 2⋅1052 \cdot 10^5. You don't know the array aa, but you know the array bb which is formed from it with the following sequence of operations:

  1. Firstly, let the array bb be equal to the array aa;
  2. Secondly, for each ii from 11 to nn:
    • if aia_i is a prime number, then one integer paip_{a_i} is appended to array bb, where pp is an infinite sequence of prime numbers (2,3,5,…2, 3, 5, \dots);
    • otherwise (if aia_i is not a prime number), the greatest divisor of aia_i which is not equal to aia_i is appended to bb;
  3. Then the obtained array of length 2n2n is shuffled and given to you in the input.

Here paip_{a_i} means the aia_i-th prime number. The first prime p1=2p_1 = 2, the second one is p2=3p_2 = 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.

出题人构造了一个由 nn 个整数组成的数组 aa;每个整数均不小于 22 且不大于 2⋅1052 \cdot 10^5。你并不知道数组 aa,但你知道由它通过以下操作生成的数组 bb:

  1. 首先,令数组 bb 等于数组 aa;
  2. 其次,对每个 ii(从 11 到 nn)执行以下操作:
    • 若 aia_i 是质数,则将一个整数 paip_{a_i} 追加到数组 bb 的末尾,其中 pp 表示质数序列(2,3,5,…2, 3, 5, \dots);
    • 否则(即 aia_i 不是质数),将 aia_i 的最大真因子(即不等于 aia_i 的最大正因子)追加到 bb 中;
  3. 最后,将得到的长度为 2n2n 的数组随机打乱,并作为输入提供给你。

此处 paip_{a_i} 表示第 aia_i 个质数:第一个质数 p1=2p_1 = 2,第二个质数 p2=3p_2 = 3,依此类推。

你的任务是恢复出任意一个满足条件的数组 aa,使其能生成给定的数组 bb。题目保证答案存在(即给定的数组 bb 确实由某个合法的数组 aa 生成)。若存在多个解,输出任意一个即可。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of elements in aa.

The second line of the input contains 2n2n integers b1,b2,…,b2nb_1, b_2, \dots, b_{2n} (2≤bi≤27501312 \le b_i \le 2750131), where bib_i is the ii-th element of bb. 27501312750131 is the 199999199999-th prime number.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数组 aa 的元素个数。

输入的第二行包含 2n2n 个整数 b1,b2,…,b2nb_1, b_2, \dots, b_{2n}(2≤bi≤27501312 \le b_i \le 2750131),其中 bib_i 是数组 bb 的第 ii 个元素。27501312750131 是第 199999199999 个质数。

输出格式

In the only line of the output print nn integers a1,a2,…,ana_1, a_2, \dots, a_n (2≤ai≤2⋅1052 \le a_i \le 2 \cdot 10^5) 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.

在输出的唯一一行中,以任意顺序打印 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(其中 2≤ai≤2⋅1052 \le a_i \le 2 \cdot 10^5)——即问题描述中所述操作序列可从该数组 aa 得到数组 bb。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    3 5 2 3 2 4

    输出#1

    3 4 2
  • 输入#2

    1
    2750131 199999

    输出#2

    199999
  • 输入#3

    1
    3 6

    输出#3

    6

输入解题思路,AI测评打分。不知道怎么写?

首页