CF2266E.Prime Destruction

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a multiset aa consisting of nn positive integers.

You may perform the following operation any number of times (possibly zero):

  • Choose an integer x>1x \gt 1 from the multiset and a prime divisor pp of xx. Remove one occurrence of xx from the multiset and add pp copies of xp\frac{x}{p}.

You are also given an integer kk (1≤k≤n1 \le k \le n). Let f(k)f(k) be the minimum number of operations required, starting from the original multiset, until every integer in the multiset is at most kk.

Find f(k)f(k).

给你一个由 nn 个正整数组成的多重集 aa。

你可以执行以下操作任意次(包括零次):

  • 从多重集中选择一个整数 x>1x \gt 1 及其一个质因数 pp。从多重集中移除一个 xx,并添加 pp 个 xp\frac{x}{p}。

你还给定一个整数 kk(1≤k≤n1 \le k \le n)。令 f(k)f(k) 表示:从原始多重集出发,经过最少多少次操作后,多重集中所有整数均不超过 kk。

求 f(k)f(k)。

输入格式

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≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5) — the initial size of the multiset and the given integer, respectively.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) — the elements of the multiset.

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≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5),分别表示多重集的初始大小和给定的整数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n),表示多重集的元素。

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

输出格式

For each test case, print a single integer f(k)f(k).

对于每个测试用例,输出一个整数 f(k)f(k)。

输入输出样例

  • 输入#1

    6
    1 1
    1
    6 2
    6 6 4 3 2 1
    8 1
    8 6 4 3 2 1 8 6
    12 3
    12 10 9 8 7 6 5 4 3 2 1 12
    10 9
    10 9 8 7 6 5 4 3 2 1
    5 5
    5 4 3 2 1

    输出#1

    0
    4
    25
    15
    1
    0

说明/提示

In the first test case, the only element is already at most kk, so no operations are needed.

In the second test case, we can perform the following operations:

[6,6,4,3,2,1]→[2,2,2,6,4,3,2,1][\color{red}{6},6,4,3,2,1] \rightarrow [\color{red}{2,2,2},6,4,3,2,1],

[2,2,2,6,4,3,2,1]→[2,2,2,2,2,2,4,3,2,1][2,2,2,\color{red}{6},4,3,2,1] \rightarrow [2,2,2,\color{red}{2,2,2},4,3,2,1],

[2,2,2,2,2,2,4,3,2,1]→[2,2,2,2,2,2,2,2,3,2,1][2,2,2,2,2,2,\color{red}{4},3,2,1] \rightarrow [2,2,2,2,2,2,\color{red}{2,2},3,2,1],

[2,2,2,2,2,2,2,2,3,2,1]→[2,2,2,2,2,2,2,2,1,1,1,2,1][2,2,2,2,2,2,2,2,\color{red}{3},2,1] \rightarrow [2,2,2,2,2,2,2,2,\color{red}{1,1,1},2,1].

Thus, 44 operations are sufficient. It can be shown that no sequence with strictly fewer operations exists.

在第一个测试用例中,唯一的元素本身已不超过 kk,因此无需任何操作。

在第二个测试用例中,我们可以执行以下操作:

[6,6,4,3,2,1]→[2,2,2,6,4,3,2,1][\color{red}{6},6,4,3,2,1] \rightarrow [\color{red}{2,2,2},6,4,3,2,1],

[2,2,2,6,4,3,2,1]→[2,2,2,2,2,2,4,3,2,1][2,2,2,\color{red}{6},4,3,2,1] \rightarrow [2,2,2,\color{red}{2,2,2},4,3,2,1],

[2,2,2,2,2,2,4,3,2,1]→[2,2,2,2,2,2,2,2,3,2,1][2,2,2,2,2,2,\color{red}{4},3,2,1] \rightarrow [2,2,2,2,2,2,\color{red}{2,2},3,2,1],

[2,2,2,2,2,2,2,2,3,2,1]→[2,2,2,2,2,2,2,2,1,1,1,2,1][2,2,2,2,2,2,2,2,\color{red}{3},2,1] \rightarrow [2,2,2,2,2,2,2,2,\color{red}{1,1,1},2,1]。

因此,44 次操作已足够。可以证明,不存在操作次数严格更少的方案。

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

首页