数组A中最大的元素数量可以通过使用操作最多可将其降低至1
Maximum number of elements in array A that can be reduced to 1 by using operation at most K times
您有一个长度N的数组A。您可以在数组的元素上执行操作(可以多次执行操作(A。在操作中,您可以将任何元素分开最小的因素大于1。您将得到Q任务。在每个任务中,您将获得一个整数K大多数k时。
输入:
第一行包含两个空间分隔的整数,n和q。
第二行包含n个空间分离的整数,表示数组a。
的元素下一个Q线包含一个整数,表示k。
的值输出:
对于每个任务,在新行中打印t th 任务的答案。
Example Input: Example Output:
3 3 1
8 9 12 3
3 0
10
1
Explanation:
Number of operations required are 3,2,3 respectively.
For the first task, we can reduce any one of the three elements to 1.
For second task, we can reduce all the elements of the array to 1.
For third task, we cannot reduce any elements to 1.
对不起我的英语。
首先,您可以建立一个eRatosthenes的筛子,但不是一个布尔值,而是保存较小的素数的信息,例如:
for (int i=4; i < MAXN; i+=2) sieve[i] = 2;
for (int i=3; i < MAXN; i+=2){
if (!sieve[i]) for (int j=i*i; j <= MAXN; j+=2*i){
if (!sieve[j]) sieve[j] = i;
} }
然后,使用筛子,您可以轻松且最佳的构建一个数组B,其中包含A中的每个元素所需的操作数量。之后,对数组B进行排序,您可以使用二进制搜索来回答查询。
相关文章:
- 对字符数组中的元素执行逐位操作
- 对 Vector 元素 (C++) 的push_back操作
- 使用现代C++在 Eigen3 矩阵上使用 for 循环进行元素操作的优雅方式
- Qt,操作缓慢时不要冻结GUI输入元素
- blaze-lib 的元素操作是否自动并行?
- 为什么用于阈值矩阵元素的 Matlab 逻辑索引操作在性能上优于 mex 实现?
- 根据堆栈操作 c++ 计算元素的最大数量
- 如何在C 对向量的第二个元素上执行较低的操作
- 阵列操作,复制最后一个元素
- 向量元素数据损坏了Find()操作
- 数组A中最大的元素数量可以通过使用操作最多可将其降低至1
- 如何在语义操作中访问元组的元素
- 在remove_if删除元素之前,我可以滥用谓词对元素执行操作吗
- 使用对其他枚举值的操作定义枚举元素值
- 在 CUDA / 推力中,如何在每个操作期间访问矢量元素的邻居?
- C++ 特征 - 如何将广播和元素操作结合起来
- C++中的元素操作
- Dlib元素特定操作
- 关于 boost::ubla 中的逐元素操作
- Rcpp犰狳:对列表元素的"-="操作