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 nn and kk, as well as an array aa consisting of nn integers, where 1≤ai≤k1 \le a_i \le k holds.

For an integer set B=b1,b2,…,bmB = {b_1, b_2, \ldots, b_m} where 1≤bi≤k1\le b_i\le k, we call it complete if and only if both of the following hold:

  • For each 1≤i≤n1\le i\le n, at least one divisor of aia_i is contained in BB;
  • For each 1≤j≤m1\le j\le m, all positive multiples of bjb_j which are less than or equal to kk appear in the array aa at least once.

You have to find a complete set BB with minimum possible size, or determine that no such set exists.

我们将那些记忆刻入了自身……无论它们多么艰难,那都是我们曾活过的人生!

——《Angel Beats!》

在来世的学校里,神山同学正在研究一个奇特的数字游戏。

她给你两个整数 nn 和 kk,以及一个由 nn 个整数组成的数组 aa,其中对每个 ii 均满足 1≤ai≤k1 \le a_i \le k。

对于一个整数集合 B={b1,b2,…,bm}B = \{b_1, b_2, \ldots, b_m\}(其中 1≤bi≤k1\le b_i\le k),当且仅当同时满足以下两个条件时,称其为完备的(complete):

  • 对每个 1≤i≤n1\le i\le n,aia_i 的至少一个正因数属于 BB;
  • 对每个 1≤j≤m1\le j\le m,所有不超过 kk 的 bjb_j 的正倍数,均在数组 aa 中至少出现一次。

你需要找出一个大小最小的完备集合 BB;若不存在这样的集合,则判定其不存在。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1≤n≤2⋅1051\le n\le 2\cdot 10^5, 1≤k≤1091\le k\le 10^9) — the length of aa and the upper bound of elements of aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤k1\le a_i\le k) — the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051\le n\le 2\cdot 10^5,1≤k≤1091\le k\le 10^9)—— 分别表示数组 aa 的长度以及 aa 中元素的上界。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤k1\le a_i\le k)—— 即数组 aa 的元素。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case:

  • If no complete set BB exists, print a single integer −1-1 in the only line of output.
  • Otherwise:
    • First print a single integer mm (1≤m≤n1\le m\le n) in the first line of output — the size of BB. Note that you have to minimize the size of BB.
    • Then output mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (1≤bi≤k1 \le b_i \le k) in the second line — the set you constructed.

If there are multiple answers, you may print any of them.

对于每个测试用例:

  • 如果不存在完整的集合 BB,则在输出的唯一一行中打印单个整数 −1-1。
  • 否则:
    • 首先在输出的第一行中打印单个整数 mm(1≤m≤n1\le m\le n)——即集合 BB 的大小。注意,你需要最小化 BB 的大小。
    • 然后在第二行输出 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(1≤bi≤k1 \le b_i \le 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,3B={2,3} works. For b=2b=2, all multiples 2,4,6{2,4,6} (up to k=6k=6) appear in aa; for b=3b=3, multiples 3,6{3,6} appear. Every aia_i is divisible by 22 or 33. No single bb can satisfy both conditions, so m=2m=2 is minimal.

In the second test case, B=1B={1} satisfies both rules since every number is divisible by 11 and all multiples of 11 up to kk appear.

在第一个测试用例中,集合 B=2,3B={2,3} 满足条件。对于 b=2b=2,所有不超过 k=6k=6 的倍数 2,4,6{2,4,6} 均出现在序列 aa 中;对于 b=3b=3,其不超过 k=6k=6 的倍数 3,6{3,6} 也均出现在 aa 中。序列中的每个元素 aia_i 均能被 22 或 33 整除。不存在单个 bb 能同时满足上述两个条件,因此最小的 mm 为 22。

在第二个测试用例中,集合 B=1B={1} 满足两个条件:因为任意整数均可被 11 整除,且所有不超过 kk 的 11 的倍数(即 1,2,…,k1,2,\dots,k)均出现在序列 aa 中。

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

首页