CF2266E.Prime Destruction
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a multiset a consisting of n positive integers.
You may perform the following operation any number of times (possibly zero):
- Choose an integer x>1 from the multiset and a prime divisor p of x. Remove one occurrence of x from the multiset and add p copies of px.
You are also given an integer k (1≤k≤n). Let f(k) be the minimum number of operations required, starting from the original multiset, until every integer in the multiset is at most k.
Find f(k).
给你一个由 n 个正整数组成的多重集 a。
你可以执行以下操作任意次(包括零次):
- 从多重集中选择一个整数 x>1 及其一个质因数 p。从多重集中移除一个 x,并添加 p 个 px。
你还给定一个整数 k(1≤k≤n)。令 f(k) 表示:从原始多重集出发,经过最少多少次操作后,多重集中所有整数均不超过 k。
求 f(k)。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤k≤n≤2⋅105) — the initial size of the multiset and the given integer, respectively.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the elements of the multiset.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤k≤n≤2⋅105),分别表示多重集的初始大小和给定的整数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n),表示多重集的元素。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, print a single integer 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 k, 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],
[2,2,2,6,4,3,2,1]→[2,2,2,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,2,2,3,2,1]→[2,2,2,2,2,2,2,2,1,1,1,2,1].
Thus, 4 operations are sufficient. It can be shown that no sequence with strictly fewer operations exists.
在第一个测试用例中,唯一的元素本身已不超过 k,因此无需任何操作。
在第二个测试用例中,我们可以执行以下操作:
[6,6,4,3,2,1]→[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,2,2,2,4,3,2,1]→[2,2,2,2,2,2,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]。
因此,4 次操作已足够。可以证明,不存在操作次数严格更少的方案。
输入解题思路,AI测评打分。不知道怎么写?