题目链接: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代码:

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<ll,int> P;
  7. const int maxn = 3e5+;
  8. P have[maxn];
  9. bool cut[maxn];
  10. bool cmp(const P &a,const P &b){
  11. return a.first>b.first;
  12. }
  13. int main(){
  14. int n;
  15. ll k,cnt=;
  16. scanf("%d%lld",&n,&k);
  17. for(int i=;i<=n;i++) have[i].first=,have[i].second=i;
  18. int m;
  19. for(m=;m<=n;m++){
  20. for(int j=m*;j<=n;j+=m) have[j].first++;
  21. cnt+=have[m].first;
  22.  
  23. if(cnt>=k) break;
  24. }
  25. if(cnt<k) return *printf("No\n");
  26. sort(have+,have+m,cmp);
  27. int temp=m;
  28. for(int i=;i<=m;i++){
  29. if(have[i].second>m/&&cnt-have[i].first>=k){
  30. cnt-=have[i].first;
  31. cut[have[i].second]=true;
  32. temp--;
  33. }
  34. if(cnt==k) break;
  35. }
  36. printf("Yes\n");
  37. printf("%d\n",temp);
  38. for(int i=;i<=m;i++){
  39. if(!cut[i]) printf("%d ",i);
  40. }
  41. printf("\n");
  42. return ;
  43. }

CF922F Divisibility的更多相关文章

  1. cf306 C. Divisibility by Eight(数学推导)

    C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 周赛-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 ...

  3. 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/ ...

  4. Divisibility by Eight (数学)

    Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. codeforces 630J Divisibility

    J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...

  6. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  7. Divisibility

    Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...

  8. HDU 3335 Divisibility (DLX)

    Divisibility Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  9. light oj 1078 - Integer Divisibility

    1078 - Integer Divisibility   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...

随机推荐

  1. oracle获取表字段及表注释的相关操作

    一.获取表字段: select * from user_tab_columns where Table_Name='用户表' user_tab_columns 为当前用户的columns,除此之外还有 ...

  2. 【Linux常见命令】tail命令

    tail - output the last part of files tail 命令可用于查看文件的内容,有一个常用的参数 -f 常用于查阅正在改变的日志文件. tail -f filename  ...

  3. 如何将Superset嵌入后台系统之实践

    1. 前言 此次实践过程全属个人学习,我选择了在window下安装Superset,并进行嵌入后台系统实践.对此进行实践过程总结,实践成果分享给大家,供大家参考,如果你有更好的想法,欢迎留言交流. 2 ...

  4. JS省城级联

    2019独角兽企业重金招聘Python工程师标准>>> 这里是HTML内容 <label class="control-label col-md-2 col-sm-3 ...

  5. DB2 Zos 浅谈 - DB2 LUW VS DB2 Zos

    DB2 Zos 浅谈 - DB2 LUW VS DB2 Zos 概述: 各位可能对DB2 LUW了解得比较多,但对DB2 Zos(大机操作系统)知之甚少,因为IBM的内部资料一向是比较封闭的,特别是我 ...

  6. Apache2.4 根目录修改

    需要修改两个地方: 1.httpd.conf 中的 DocumentRoot 项 和 Directory 项 2.httpd-vhosts.conf 中的 DocumentRoot 项 网上找到的大部 ...

  7. Vim Install-Could not get lock......

    在Ubuntu下安装Vim编辑器时,出现错误: 可能原因: 上次安装或更新没有正常完成,导致资源被锁. 解决方案: 删除异常资源,重新下载: 注意 删除异常资源时,一定要切换到root用户,否则操作无 ...

  8. C语言编程入门题目--No.12

    题目:判断101-200之间有多少个素数,并输出所有素数. 1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数. 2.程序源代码: # ...

  9. POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)

    这个题是说有C头牛去晒太阳,带了L瓶防晒霜,每瓶防晒霜都有一个SPF值(每瓶防晒霜都能解决一个最短路 ) 每头牛给出了他可以接受防晒霜的上限,和下限,每种防晒霜都给出了SPF值与数量. 从防晒霜的sp ...

  10. spark-2.4.5 安装记录

    参考 https://data-flair.training/blogs/install-apache-spark-multi-node-cluster/ 下载 spark 地址为 http://sp ...