311183: CF1945H. GCD is Greater

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. GCD is Greatertime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

In the evenings during the hike, Kirill and Anton decided to take out an array of integers $a$ of length $n$ from their backpack and play a game with it. The rules are as follows:

  1. Kirill chooses from $2$ to $(n-2)$ numbers and encircles them in red.
  2. Anton encircles all the remaining numbers in blue.
  3. Kirill calculates the greatest common divisor (GCD) of all the red numbers.
  4. Anton calculates the bitwise AND of all the blue numbers and adds the number $x$ to the result.
  5. If the GCD of all the red numbers is strictly greater than the sum of the bitwise AND of all the blue numbers and the number $x$, then Kirill wins; otherwise, Anton wins.

Help Kirill to beat Anton or tell if it's impossible.

Input

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 20\,000$) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers $n$ and $x$ ($4\le n \le 4\cdot 10^5$, $0 \le x \le 4\cdot 10^5$) — the number of integers and the number $x$ respectively.

The second line contains an array $a$ of length $n$ ($1 \le a_i \le 4\cdot 10^5$).

It is guaranteed that the sum of $n$ for all test cases does not exceed $4\cdot 10^5$. It is also guaranteed that the sum of the maximum values of $a_i$ for each test case does not exceed $4\cdot 10^5$.

Output

For each test case, output "YES" on the first line if the condition can be met, on the second line, output the number of chosen numbers by Kirill and the numbers themselves in any order separated by a space, and on the third line, output the size of the second set and the numbers in it.

Otherwise, output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

ExampleInput
8
4 1
4 3 1 8
4 1
4 5 8 4
5 0
1 1 1 1 1
5 2
31 63 127 63 31
4 1
1 3 3 3
8 3
4 3 4 1 2 2 5 3
4 2
1 4 3 6
8 48
31 61 37 15 53 26 61 12
Output
YES
2 4 8
2 3 1 
YES
2 4 4
2 5 8 
NO
YES
2 63 63
3 31 127 31
YES
2 3 3
2 1 3
YES
2 4 4
6 3 1 2 2 5 3
YES
2 3 6
2 1 4 
YES
2 61 61
6 31 37 15 53 26 12

Output

**题目大意:**

Kirill 和 Anton 在徒步旅行中晚上无聊时,决定拿出一个长度为 $ n $ 的整数数组 $ a $ 来玩游戏。游戏规则如下:

1. Kirill 从数组中选择 2 到 $ n-2 $ 个数字,并将它们标记为红色。
2. Anton 将剩下的所有数字标记为蓝色。
3. Kirill 计算所有红色数字的最大公约数(GCD)。
4. Anton 计算所有蓝色数字的按位与(bitwise AND),并将数字 $ x $ 加到结果中。
5. 如果所有红色数字的 GCD 严格大于所有蓝色数字的按位与结果加上数字 $ x $,则 Kirill 获胜;否则,Anton 获胜。

帮助 Kirill 击败 Anton,或者判断是否不可能。

**输入数据格式:**

每个测试包含多个测试用例。第一行包含一个整数 $ t $ ($ 1 \le t \le 20,000 $) —— 测试用例的数量。然后是测试用例的描述。

每个测试用例的第一行包含两个整数 $ n $ 和 $ x $ ($ 4 \le n \le 4 \times 10^5 $, $ 0 \le x \le 4 \times 10^5 $) —— 整数的数量和数字 $ x $。

第二行包含一个长度为 $ n $ 的数组 $ a $ ($ 1 \le a_i \le 4 \times 10^5 $)。

保证所有测试用例的 $ n $ 之和不超过 $ 4 \times 10^5 $。同时保证每个测试用例的 $ a_i $ 的最大值之和不超过 $ 4 \times 10^5 $。

**输出数据格式:**

对于每个测试用例,如果满足条件,则在第一行输出 "YES",在第二行输出 Kirill 选择的数字的数量和这些数字(可以按任何顺序),用空格分隔,在第三行输出第二组数字的大小和这些数字。

否则,输出 "NO"。

你可以以任何大小写输出每个字母。例如,"yEs"、"yes"、"Yes" 和 "YES" 都将作为肯定答案被接受。**题目大意:** Kirill 和 Anton 在徒步旅行中晚上无聊时,决定拿出一个长度为 $ n $ 的整数数组 $ a $ 来玩游戏。游戏规则如下: 1. Kirill 从数组中选择 2 到 $ n-2 $ 个数字,并将它们标记为红色。 2. Anton 将剩下的所有数字标记为蓝色。 3. Kirill 计算所有红色数字的最大公约数(GCD)。 4. Anton 计算所有蓝色数字的按位与(bitwise AND),并将数字 $ x $ 加到结果中。 5. 如果所有红色数字的 GCD 严格大于所有蓝色数字的按位与结果加上数字 $ x $,则 Kirill 获胜;否则,Anton 获胜。 帮助 Kirill 击败 Anton,或者判断是否不可能。 **输入数据格式:** 每个测试包含多个测试用例。第一行包含一个整数 $ t $ ($ 1 \le t \le 20,000 $) —— 测试用例的数量。然后是测试用例的描述。 每个测试用例的第一行包含两个整数 $ n $ 和 $ x $ ($ 4 \le n \le 4 \times 10^5 $, $ 0 \le x \le 4 \times 10^5 $) —— 整数的数量和数字 $ x $。 第二行包含一个长度为 $ n $ 的数组 $ a $ ($ 1 \le a_i \le 4 \times 10^5 $)。 保证所有测试用例的 $ n $ 之和不超过 $ 4 \times 10^5 $。同时保证每个测试用例的 $ a_i $ 的最大值之和不超过 $ 4 \times 10^5 $。 **输出数据格式:** 对于每个测试用例,如果满足条件,则在第一行输出 "YES",在第二行输出 Kirill 选择的数字的数量和这些数字(可以按任何顺序),用空格分隔,在第三行输出第二组数字的大小和这些数字。 否则,输出 "NO"。 你可以以任何大小写输出每个字母。例如,"yEs"、"yes"、"Yes" 和 "YES" 都将作为肯定答案被接受。

加入题单

上一题 下一题 算法标签: