CF922F Divisibility
题目链接:http://codeforces.com/contest/922/problem/F
题目大意:
对于一个数集 \(I\),定义 \(f(I)\) 为 \(I\) 中满足条件的数对\((a,b)\)的个数:\(a<b\) 并且 \(a|b\).
要求构造一个数集 \(I\),数集中元素大于 \(0\) 小于等于 \(n\),并且 \(f(I) = k\).
知识点: 构造
解题思路:
用一种类似素数筛的方法计算每个数的真因子的个数,顺便把个数累加起来,一旦发现大于等于\(k\)即可停止,我们用这些数来构造即可。当然,如果发现 \(1\) 到 \(n\) 所有的真因子个数加起来都小于 \(k\),直接输出 "\(No\)".
接下来根据真因子个数从大到小排序,如果找到一个 \(x\) 满足:\(x > m/2\) 并且目前的 \(f( )\) 值减掉这个数真因子数大于或等于 \(k\),就在数集中去除这个数并且更新 \(f()\) 值(因为对于大于 \(m/2\) 的数,它对于答案的贡献便是其真因子数),直到满足 \(f(I) = k\) 即可。(具体证明参考官方题解)
AC代码:
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,int> P;
- const int maxn = 3e5+;
- P have[maxn];
- bool cut[maxn];
- bool cmp(const P &a,const P &b){
- return a.first>b.first;
- }
- int main(){
- int n;
- ll k,cnt=;
- scanf("%d%lld",&n,&k);
- for(int i=;i<=n;i++) have[i].first=,have[i].second=i;
- int m;
- for(m=;m<=n;m++){
- for(int j=m*;j<=n;j+=m) have[j].first++;
- cnt+=have[m].first;
- if(cnt>=k) break;
- }
- if(cnt<k) return *printf("No\n");
- sort(have+,have+m,cmp);
- int temp=m;
- for(int i=;i<=m;i++){
- if(have[i].second>m/&&cnt-have[i].first>=k){
- cnt-=have[i].first;
- cut[have[i].second]=true;
- temp--;
- }
- if(cnt==k) break;
- }
- printf("Yes\n");
- printf("%d\n",temp);
- for(int i=;i<=m;i++){
- if(!cut[i]) printf("%d ",i);
- }
- printf("\n");
- return ;
- }
CF922F Divisibility的更多相关文章
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏
Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Divisibility by Eight (数学)
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Divisibility
Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...
- HDU 3335 Divisibility (DLX)
Divisibility Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- light oj 1078 - Integer Divisibility
1078 - Integer Divisibility PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
随机推荐
- oracle获取表字段及表注释的相关操作
一.获取表字段: select * from user_tab_columns where Table_Name='用户表' user_tab_columns 为当前用户的columns,除此之外还有 ...
- 【Linux常见命令】tail命令
tail - output the last part of files tail 命令可用于查看文件的内容,有一个常用的参数 -f 常用于查阅正在改变的日志文件. tail -f filename ...
- 如何将Superset嵌入后台系统之实践
1. 前言 此次实践过程全属个人学习,我选择了在window下安装Superset,并进行嵌入后台系统实践.对此进行实践过程总结,实践成果分享给大家,供大家参考,如果你有更好的想法,欢迎留言交流. 2 ...
- JS省城级联
2019独角兽企业重金招聘Python工程师标准>>> 这里是HTML内容 <label class="control-label col-md-2 col-sm-3 ...
- DB2 Zos 浅谈 - DB2 LUW VS DB2 Zos
DB2 Zos 浅谈 - DB2 LUW VS DB2 Zos 概述: 各位可能对DB2 LUW了解得比较多,但对DB2 Zos(大机操作系统)知之甚少,因为IBM的内部资料一向是比较封闭的,特别是我 ...
- Apache2.4 根目录修改
需要修改两个地方: 1.httpd.conf 中的 DocumentRoot 项 和 Directory 项 2.httpd-vhosts.conf 中的 DocumentRoot 项 网上找到的大部 ...
- Vim Install-Could not get lock......
在Ubuntu下安装Vim编辑器时,出现错误: 可能原因: 上次安装或更新没有正常完成,导致资源被锁. 解决方案: 删除异常资源,重新下载: 注意 删除异常资源时,一定要切换到root用户,否则操作无 ...
- C语言编程入门题目--No.12
题目:判断101-200之间有多少个素数,并输出所有素数. 1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数. 2.程序源代码: # ...
- POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)
这个题是说有C头牛去晒太阳,带了L瓶防晒霜,每瓶防晒霜都有一个SPF值(每瓶防晒霜都能解决一个最短路 ) 每头牛给出了他可以接受防晒霜的上限,和下限,每种防晒霜都给出了SPF值与数量. 从防晒霜的sp ...
- spark-2.4.5 安装记录
参考 https://data-flair.training/blogs/install-apache-spark-multi-node-cluster/ 下载 spark 地址为 http://sp ...