Codeforces Round 1068 (Div. 2)
C
Kanade's Perfect Multiples
Codeforces
1400
原题
← BD →
翻译中…

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 \le a_i \le k$ holds.

翻译中…

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

翻译中…
  • For each $1\le i\le n$, at least one divisor of $a_i$ is contained in $B$;
  • For each $1\le j\le m$, all positive multiples of $b_j$ 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.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1\le n\le 2\cdot 10^5$, $1\le k\le 10^9$) — the length of $a$ and the upper bound of elements of $a$.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\le a_i\le k$) — the elements of $a$.

翻译中…

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

翻译中…

Output

翻译中…

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\le m\le 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 $b_1, b_2, \ldots, b_m$ ($1 \le b_i \le k$) in the second line — the set you constructed.
翻译中…

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

翻译中…

Note

翻译中…

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 $a_i$ 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.

翻译中…

样例

Input #1
4
4 6
3 2 4 6
5 5
1 2 3 4 5
3 6
2 3 6
1 2
2
Output #1
2
2 3
1
1
-1
1
2
InputCopy OutputCopy
题目信息
题号
2173C
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
贪心
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。