Universal Cup Judging System

Universal Cup

时间限制: 1.0 s 内存限制: 64 MB 总分: 100 可 Hack ✓
统计

给定一个包含 $n$ 个整数的数组 $a_1, a_2, \dots, a_n$,如果 $i \neq j$ 且 $a_i + a_j$ 为素数,则称集合 $\{i, j\}$ 为该数组的一个素数集。

BaoBao 刚刚在他的口袋里发现了一个包含 $n$ 个整数的数组 $a_1, a_2, \dots, a_n$。他想选择至多 $k$ 个该数组的素数集,以最大化所选集合并集的大小。也就是说,通过仔细选择 $m$ 和 $p_1, p_2, \dots, p_m$(其中 $m \le k$ 且 $p_i$ 是该数组的一个素数集),来最大化 $|\bigcup_{i=1}^m p_i|$。

请帮助 BaoBao 计算并集的最大大小。

输入格式

输入包含多组测试数据。输入的第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 3 \times 10^3$, $0 \le k \le \frac{n(n-1)}{2}$),其含义如上所述。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$),表示给定的数组。

保证所有测试数据的 $n$ 之和不超过 $10^4$。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示选择至多 $k$ 个素数集后,并集的最大大小。

样例

输入 1

4
4 2
2 3 4 5
5 3
3 4 12 3 6
6 3
1 3 6 8 1 1
1 0
1

输出 1

4
3
6
0

说明

对于第一个样例,共有 3 个素数集:$\{1, 2\}, \{1, 4\}$ 和 $\{2, 3\}$。由于 $k = 2$,我们可以选择 $\{1, 4\}$ 和 $\{2, 3\}$,得到最大的并集 $\{1, 2, 3, 4\}$,大小为 4。

对于第二个样例,只有 2 个素数集:$\{1, 2\}$ 和 $\{2, 4\}$。由于 $k = 3$,我们可以选择这两个集合,得到最大的并集 $\{1, 2, 4\}$,大小为 3。

对于第三个样例,共有 7 个素数集:$\{1, 3\}, \{1, 5\}, \{1, 6\}, \{2, 4\}, \{3, 5\}, \{3, 6\}$ 和 $\{5, 6\}$。由于 $k = 3$,我们可以选择 $\{1, 3\}, \{2, 4\}$ 和 $\{5, 6\}$,得到最大的并集 $\{1, 2, 3, 4, 5, 6\}$,大小为 6。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.