Divisibility

我们考虑删数字

首先我们可以发现有一类数很特殊就是大于 n / 2的素数, 因为这些素数的贡献只有1, 并且在n大的时候,

这些素数的个数不是很少, 我们可以最后用这些数去调整, 并且删掉一个数的时候删掉的是它的因子个数,

所以可以用素数去控制最后的数量。当n小的时候直接状压枚举。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11.  
  12. using namespace std;
  13.  
  14. const int N = 1e6 + ;
  15. const int inf = 0x3f3f3f3f;
  16. const LL INF = 0x3f3f3f3f3f3f3f3f;
  17. const int mod = 1e9 + ;
  18. const double eps = 1e-;
  19. const double PI = acos(-);
  20.  
  21. int n;
  22. LL k;
  23. int rel[N];
  24. bool vis[N];
  25. int now;
  26. vector<int> vc;
  27. set<int> Set;
  28. vector<int> fac[N];
  29.  
  30. int main() {
  31. scanf("%d%lld", &n, &k);
  32. if(n <= ) {
  33. vector<int> ret;
  34. for(int S = ; S < ( << n); S++) {
  35. ret.clear();
  36. for(int i = ; i < n; i++)
  37. if(S >> i & ) ret.push_back(i + );
  38. int cnt = ;
  39. for(int i = ; i < SZ(ret); i++) {
  40. for(int j = i + ; j < SZ(ret); j++) {
  41. if(ret[j] % ret[i] == ) {
  42. cnt++;
  43. }
  44. }
  45. }
  46. if(cnt == k) {
  47. puts("Yes");
  48. printf("%d\n", SZ(ret));
  49. for(auto& t : ret) printf("%d ", t);
  50. puts("");
  51. return ;
  52. }
  53. }
  54. puts("No");
  55. } else {
  56. for(int i = ; i <= n; i++) {
  57. for(int j = i + i; j <= n; j += i)
  58. vis[j] = true;
  59. }
  60. for(int i = ; i <= n; i++) Set.insert(i);
  61. for(int i = ; i <= n; i++) {
  62. for(int j = i + i; j <= n; j += i) {
  63. now++;
  64. rel[j]++;
  65. rel[i]++;
  66. fac[j].push_back(i);
  67. }
  68. }
  69. if(now < k) {
  70. puts("No");
  71. return ;
  72. }
  73. if(now == k) {
  74. puts("Yes");
  75. printf("%d\n", SZ(Set));
  76. for(auto& t : Set) printf("%d ", t);
  77. puts("");
  78. return ;
  79. }
  80. for(int i = n / + ; i <= n; i++) {
  81. if(!vis[i]) {
  82. vc.push_back(i), now--, Set.erase(i);
  83. rel[]--;
  84. if(now == k) {
  85. puts("Yes");
  86. printf("%d\n", SZ(Set));
  87. for(auto& t : Set) printf("%d ", t);
  88. puts("");
  89. return ;
  90. }
  91. }
  92. }
  93. while(now > k) {
  94. int v = *Set.rbegin();
  95. if(rel[v] <= now - k) {
  96. now -= rel[v];
  97. Set.erase(v);
  98. for(auto& t : fac[v]) rel[t]--;
  99. } else {
  100. int who = v;
  101. for(auto& t : Set)
  102. if(now - rel[t] <= k && rel[t] < rel[who]) who = t;
  103. now -= rel[who];
  104. Set.erase(who);
  105. for(auto& t : fac[who]) rel[t]--;
  106. while(now < k && SZ(vc)) {
  107. now++;
  108. Set.insert(vc.back());
  109. vc.pop_back();
  110. }
  111. }
  112. }
  113. if(now == k) {
  114. puts("Yes");
  115. printf("%d\n", SZ(Set));
  116. for(auto& t : Set) printf("%d ", t);
  117. puts("");
  118. return ;
  119. } else {
  120. puts("No");
  121. }
  122. }
  123. return ;
  124. }
  125.  
  126. /*
  127. */

Codeforces 922F Divisibility 构造的更多相关文章

  1. Codeforces 922F Divisibility (构造 + 数论)

    题目链接  Divisibility 题意 给定$n$和$k$,构造一个集合$\left\{1, 2, 3, ..., n \right\}$的子集,使得在这个集合中恰好有$k$对正整数$(x, y) ...

  2. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  3. Codeforces 550C —— Divisibility by Eight——————【枚举 || dp】

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

  4. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

  5. [math] Codeforces 597A Divisibility

    题目:http://codeforces.com/problemset/problem/597/A Divisibility time limit per test 1 second memory l ...

  6. Codeforces Global Round 8 B. Codeforces Subsequences(构造)

    题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...

  7. Codeforces 410C.Team[构造]

    C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  8. Codeforces 716C[数论][构造]

    /* CF傻逼构造题 某人要经过n回合游戏,初始分值是2,等级为1. 每次有两种操作 1.无条件,分值加上自己的等级数. 2.当目前的数字是完全平方数并且该数字开方以后是等级数加1的整数倍,那么可以将 ...

  9. codeforces 630J Divisibility

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

随机推荐

  1. how to avoid inheritance abuse

    Liskov Principle: if S is a subtype of Type T, then any objects of type T may be repalced by objects ...

  2. 并发性能的隐形杀手之伪共享(false sharing)

    在并发编程过程中,我们大部分的焦点都放在如何控制共享变量的访问控制上(代码层面),但是很少人会关注系统硬件及 JVM 底层相关的影响因素.前段时间学习了一个牛X的高性能异步处理框架 Disruptor ...

  3. centos6.5 python命令行模式左右建无法使用

    我的虚拟机是centos6.5,自带python2.6:安装了Python2.7(安装了pip管理工具)后,在python2.7命令行模式下,左右键及退格键无法使用,基于以上情况,我进行了百度: 第一 ...

  4. 分析Vue框架源码心得

    1.在封装一个公用组件,比如button按钮,我们多个地方使用,不同类型的button调用不同的方法,我们就可以这样用 代码片段: <lin-button v-for="(item,i ...

  5. 随机生成n位随机数(包含大写字母、小写字母、数字)

    package com.java.weiju; import java.security.SecureRandom; import java.util.Date; import java.util.R ...

  6. Confluence 6 启用主题评论

    页面或者博客页面中显示的评论以下面 2 种方式显示: 主题模式(Threaded):以继承回复的方式显示页面的评论.每一回复的评论将会在不同评论之间显示,以表示各个评论之间的关系. 平面模式(Flat ...

  7. Confluence 6 SQL Server 测试你的数据库连接

    在你的数据库设置界面,有一个 测试连接(Test connection)按钮可以检查: Confluence 可以连接你的数据库服务器 数据库字符集和隔离级别是正确的 你的数据库用户有正确的数据库权限 ...

  8. Confluence 6 布局高级自定义

    重载 Velocity 模板 velocity 目录是 Confluence Velocity 模板文件进行搜索时候需要的文件夹.例如,你可以通过将你的 Velocity 文件使用正确的文件名放置到正 ...

  9. 高性能JavaScript读后感

    这本书让lz对js性能优化有了更深刻的理解,现在因为我们通常用第三方构建工具webpack.gulp等诸如此类,之前总是听说什么dom操作影响性能呢,对这个概念总是有点模糊,但看完这本书之后后,相对而 ...

  10. gnuradio 创建cos_source

    C++教程 ys_linux@computer:~$ gr_modtool nm kcd Creating out-of-tree module in ./gr-kcd... Done. Use 'g ...