CF2173C.Kanade's Perfect Multiples
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We've carved those memories into ourselves... No matter how hard they were, they're the lives we carried out!
— Angel Beats!
In the afterlife school, Kanade studies a peculiar number game.
She gives you two integers n and k, as well as an array a consisting of n integers, where 1≤ai≤k holds.
For an integer set B=b1,b2,…,bm where 1≤bi≤k, we call it complete if and only if both of the following hold:
- For each 1≤i≤n, at least one divisor of ai is contained in B;
- For each 1≤j≤m, all positive multiples of bj which are less than or equal to k appear in the array a at least once.
You have to find a complete set B with minimum possible size, or determine that no such set exists.
我们将那些记忆刻入了自身……无论它们多么艰难,那都是我们曾活过的人生!
——《Angel Beats!》
在来世的学校里,神山同学正在研究一个奇特的数字游戏。
她给你两个整数 n 和 k,以及一个由 n 个整数组成的数组 a,其中对每个 i 均满足 1≤ai≤k。
对于一个整数集合 B={b1,b2,…,bm}(其中 1≤bi≤k),当且仅当同时满足以下两个条件时,称其为完备的(complete):
- 对每个 1≤i≤n,ai 的至少一个正因数属于 B;
- 对每个 1≤j≤m,所有不超过 k 的 bj 的正倍数,均在数组 a 中至少出现一次。
你需要找出一个大小最小的完备集合 B;若不存在这样的集合,则判定其不存在。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤n≤2⋅105, 1≤k≤109) — the length of a and the upper bound of elements of a.
The second line contains n integers a1,a2,…,an (1≤ai≤k) — the elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105,1≤k≤109)—— 分别表示数组 a 的长度以及 a 中元素的上界。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤k)—— 即数组 a 的元素。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case:
- If no complete set B exists, print a single integer −1 in the only line of output.
- Otherwise:
- First print a single integer m (1≤m≤n) in the first line of output — the size of B. Note that you have to minimize the size of B.
- Then output m integers b1,b2,…,bm (1≤bi≤k) in the second line — the set you constructed.
If there are multiple answers, you may print any of them.
对于每个测试用例:
- 如果不存在完整的集合 B,则在输出的唯一一行中打印单个整数 −1。
- 否则:
- 首先在输出的第一行中打印单个整数 m(1≤m≤n)——即集合 B 的大小。注意,你需要最小化 B 的大小。
- 然后在第二行输出 m 个整数 b1,b2,…,bm(1≤bi≤k)——即你构造出的集合。
如果存在多个答案,你可以输出其中任意一个。
输入输出样例
输入#1
4 4 6 3 2 4 6 5 5 1 2 3 4 5 3 6 2 3 6 1 2 2
输出#1
2 2 3 1 1 -1 1 2
说明/提示
In the first test case, B=2,3 works. For b=2, all multiples 2,4,6 (up to k=6) appear in a; for b=3, multiples 3,6 appear. Every ai is divisible by 2 or 3. No single b can satisfy both conditions, so m=2 is minimal.
In the second test case, B=1 satisfies both rules since every number is divisible by 1 and all multiples of 1 up to k appear.
在第一个测试用例中,集合 B=2,3 满足条件。对于 b=2,所有不超过 k=6 的倍数 2,4,6 均出现在序列 a 中;对于 b=3,其不超过 k=6 的倍数 3,6 也均出现在 a 中。序列中的每个元素 ai 均能被 2 或 3 整除。不存在单个 b 能同时满足上述两个条件,因此最小的 m 为 2。
在第二个测试用例中,集合 B=1 满足两个条件:因为任意整数均可被 1 整除,且所有不超过 k 的 1 的倍数(即 1,2,…,k)均出现在序列 a 中。
输入解题思路,AI测评打分。不知道怎么写?