CF1468L.Prime Divisors Selection

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Suppose you have a sequence of kk integers A=[a1,a2,…,ak]A = [a_1, a_2, \dots , a_k] where each ai≥2a_i \geq 2. A sequence of prime integers P=[p1,p2,…,pk]P = [p_1, p_2, \dots, p_k] is called suitable for the sequence AA if a1a_1 is divisible by p1p_1, a2a_2 is divisible by p2p_2 and so on.

A sequence of prime integers PP is called friendly if there are no unique integers in this sequence.

A sequence AA is called ideal, if each sequence PP that is suitable for AA is friendly as well (i. e. there is no sequence PP that is suitable for AA, but not friendly). For example, the sequence [2,4,16][2, 4, 16] is ideal, while the sequence [2,4,6][2, 4, 6] is not ideal (there exists a sequence P=[2,2,3]P = [2, 2, 3] which is suitable for AA, but not friendly).

You are given nn different integers x1x_1, x2x_2, ..., xnx_n. You have to choose exactly kk of them in such a way that they form an ideal sequence, or report that it is impossible. Note that no integer can be chosen more than once.

假设你有一个由 kk 个整数构成的序列 A=[a1,a2,…,ak]A = [a_1, a_2, \dots , a_k],其中每个 ai≥2a_i \geq 2。一个由素数组成的序列 P=[p1,p2,…,pk]P = [p_1, p_2, \dots, p_k] 被称为适用于序列 AA,当且仅当 a1a_1 被 p1p_1 整除、a2a_2 被 p2p_2 整除,依此类推。

一个由素数组成的序列 PP 被称为友好的,当且仅当该序列中不存在唯一的(即只出现一次的)整数。

若序列 AA 满足:每一个适用于 AA 的序列 PP 都是友好的(即:不存在某个适用于 AA 却不友好的序列 PP),则称 AA 为理想的。例如,序列 [2,4,16][2, 4, 16] 是理想的,而序列 [2,4,6][2, 4, 6] 不是理想的(因为存在一个适用于 AA 却不友好的序列 P=[2,2,3]P = [2, 2, 3])。

现给你 nn 个互不相同的整数 x1x_1, x2x_2, ..., xnx_n。你需要从中恰好选出 kk 个数,使得它们构成一个理想的序列;若不可能,则报告无解。注意:每个整数至多只能被选一次。

输入格式

The first line contains two integers nn and kk (1≤k≤n≤10001 \leq k \leq n \leq 1000).

The second line contains nn pairwise distinct integers x1x_1, x2x_2, ..., xnx_n (2≤xi≤10182 \leq x_i \leq 10^{18}).

第一行包含两个整数 nn 和 kk(1≤k≤n≤10001 \leq k \leq n \leq 1000)。

第二行包含 nn 个两两不同的整数 x1x_1, x2x_2, ..., xnx_n(2≤xi≤10182 \leq x_i \leq 10^{18})。

输出格式

If it is impossible to choose exactly kk integers from x1x_1, x2x_2, ..., xnx_n in such a way that the chosen integers form an ideal sequence, print 00.

Otherwise, print kk pairwise distinct integers — the elements of the chosen ideal sequence. If there are multiple answers, print any of them.

如果无法从 x1x_1, x2x_2, ..., xnx_n 中恰好选出 kk 个整数,使得所选整数构成一个理想序列,则输出 00。

否则,输出 kk 个两两不同的整数——即所选理想序列的元素。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3 3
    2 4 6

    输出#1

    0
  • 输入#2

    3 3
    2 4 16

    输出#2

    2 4 16
  • 输入#3

    4 3
    2 4 6 16

    输出#3

    2 4 16

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

首页