CF1468L.Prime Divisors Selection
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose you have a sequence of k integers A=[a1,a2,…,ak] where each ai≥2 . A sequence of prime integers P=[p1,p2,…,pk] is called suitable for the sequence A if a1 is divisible by p1 , a2 is divisible by p2 and so on.
A sequence of prime integers P is called friendly if there are no unique integers in this sequence.
A sequence A is called ideal, if each sequence P that is suitable for A is friendly as well (i. e. there is no sequence P that is suitable for A , but not friendly). For example, the sequence [2,4,16] is ideal, while the sequence [2,4,6] is not ideal (there exists a sequence P=[2,2,3] which is suitable for A , but not friendly).
You are given n different integers x1 , x2 , ..., xn . You have to choose exactly k 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.
输入格式
The first line contains two integers n and k ( 1≤k≤n≤1000 ).
The second line contains n pairwise distinct integers x1 , x2 , ..., xn ( 2≤xi≤1018 ).
输出格式
If it is impossible to choose exactly k integers from x1 , x2 , ..., xn in such a way that the chosen integers form an ideal sequence, print 0 .
Otherwise, print k pairwise distinct integers — the elements of the chosen ideal sequence. If there are multiple answers, print any of them.
输入输出样例
输入#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