Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)
H
Rayan vs. Rayaneh
Codeforces
3300
原题
← G2→
翻译中…

Rayan makes his final efforts to win Reyhaneh's heart by claiming he is stronger than Rayaneh (i.e., computer in Persian). To test this, Reyhaneh asks Khwarizmi for help. Khwarizmi explains that a set is integer linearly independent if no element in the set can be written as an integer linear combination of the others. Rayan is given a set of integers each time and must identify one of the largest possible integer linearly independent subsets.

翻译中…

Note that a single element is always considered an integer linearly independent subset.

翻译中…

An integer linearly combination of $a_1, \ldots, a_k$ is any sum of the form $c_1 \cdot a_1 + c_2 \cdot a_2 + \ldots + c_k \cdot a_k$ where $c_1, c_2, \ldots, c_k$ are integers (which may be zero, positive, or negative).

翻译中…

Input

翻译中…

The first line contains an integer $t$ ($1 \leq t \leq 100$), the number of test cases.

翻译中…

The first line of each test case contains an integer $n$ ($1 \leq n \leq 10^5$), the size of the set. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^5$).

翻译中…

The sum of $n$ over all test cases does not exceed $3 \cdot 10^6$.

翻译中…

Output

翻译中…

In the first line of each test case print the size of the largest integer linearly independent subset.

翻译中…

In the next line, print one such subset in any order. If there are multiple valid subsets, print any one of them.

翻译中…

Note

翻译中…

In example 1, $\{4, 6\}$ is an integer linearly independent subset. It can be proven that there is no integer linearly independent subset with at least $3$ elements.

翻译中…

In example 2, $\{35, 21, 30\}$ is an integer linearly independent subset because no integer linear combination of any two elements can create the third. There is no integer linearly independent subset with at least $4$ elements.

翻译中…

In example 3, $\{2, 3, 6\}$ is not an integer linearly independent subset since $6$ can be written as $6 \cdot 2 + (-2) \cdot 3$, which is an integer linear combination of $\{2, 3\}$.

翻译中…

样例

Input #1
3
5
2 4 6 8 10
5
12 15 21 30 35
3
2 3 6
Output #1
2
4 6
3
35 21 30
2
2 3
InputCopy OutputCopy
题目信息
题号
2034H
时间限制
4 s
内存限制
512 MB
标签
暴力
DFS 及类似
动态规划
数论

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