Codeforces 922F Divisibility (构造 + 数论)
题目链接 Divisibility
题意 给定$n$和$k$,构造一个集合$\left\{1, 2, 3, ..., n \right\}$的子集,使得在这个集合中恰好有$k$对正整数$(x, y)$, $x < y$
满足$x$是$y$的约数。
选定$1$和$2$,
首先把满足 $x > [\frac{n}{2}]\ $的质数$x$留出来,
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 3e5 + 10; int a[N], b[N], c[N], f[N];
int n, k, num1 = 0, num2 = 0;
vector <int> c1, c21, c22;
vector <int> ans; void print(){
puts("Yes");
sort(ans.begin(), ans.end());
int sz = ans.size(); printf("%d\n", sz);
int fg = 0;
for (auto u : ans){
if (!fg) fg = 1;
else putchar(32);
printf("%d", u);
} putchar(10);
exit(0);
} void calc(){
int x1 = c1.size(), x21 = c21.size(), x22 = c22.size();
if (k & 1){
if (num1 == 0){ puts("No"); exit(0);} while (k >= 3 && x22 > 0){
k -= 2;
--x22;
ans.push_back(c22[x22]);
c22.pop_back();
} while (k >= 3 && x21 > 0){
k -= 2;
--x21;
ans.push_back(c21[x21]);
c21.pop_back();
} while (k > 0 && x1 > 0){
k--;
--x1;
ans.push_back(c1[x1]);
c1.pop_back();
} if (k > 0){ puts("No"); exit(0); }
print();
} else{
while (k >= 2 && x22 > 0){
k -= 2;
--x22;
ans.push_back(c22[x22]);
c22.pop_back();
} while (k >= 2 && x21 > 0){
k -= 2;
--x21;
ans.push_back(c21[x21]);
c21.pop_back();
} while (k > 0 && x1 > 0){
k--;
--x1;
ans.push_back(c1[x1]);
c1.pop_back();
} if (k > 0){ puts("No"); exit(0);}
print();
}
} int main(){ scanf("%d%d", &n, &k); rep(i, 2, 3e5 + 1){
if (!b[i]){
for (int j = i + i; j <= 3e5 + 1; j += i)
b[j] = 1;
}
} rep(i, 1, 3e5 + 1){
for (int j = i; j <= 3e5 + 1; j += i) ++f[j];
--f[i];
} c[1] = 1, c[2] = 1;
rep(i, n / 2 + 1, n) if (!b[i]){
if (i <= 2) continue;
c[i] = 1;
c1.push_back(i);
++num1;
} rep(i, n / 3 + 1, n / 2) if (!b[i]){
if (i <= 2) continue;
c[i] = 1;
c[i << 1] = 1;
c21.push_back(i);
c22.push_back(i * 2);
++num2;
} --k;
ans.push_back(1);
ans.push_back(2);
if (k == 0) print(); rep(i, 3, n){
if (c[i]) continue;
if (k >= f[i]){
k -= f[i];
ans.push_back(i);
}
else calc();
} calc();
return 0;
}
Codeforces 922F Divisibility (构造 + 数论)的更多相关文章
- Codeforces 922F Divisibility 构造
Divisibility 我们考虑删数字 首先我们可以发现有一类数很特殊就是大于 n / 2的素数, 因为这些素数的贡献只有1, 并且在n大的时候, 这些素数的个数不是很少, 我们可以最后用这些数去调 ...
- CF45G Prime Problem 构造+数论
正解:构造+数论 解题报告: 传送门! maya这题好神仙啊我jio得,,,反正我当初听的时候是没有太懂的,,, 首先这题你要知道一些必要的数学姿势 比如哥德巴赫猜想巴拉巴拉的 然后直接讲题趴QAQ ...
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- [CodeForces - 1225C]p-binary 【数论】【二进制】
[CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...
- codeforces 487C C. Prefix Product Sequence(构造+数论)
题目链接: C. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces 550C —— Divisibility by Eight——————【枚举 || dp】
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
- [math] Codeforces 597A Divisibility
题目:http://codeforces.com/problemset/problem/597/A Divisibility time limit per test 1 second memory l ...
- Codeforces Global Round 8 B. Codeforces Subsequences(构造)
题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...
随机推荐
- docker 学习(1)
Docker与容器和虚拟机 Docker跟虚拟机有什么区别啊?这个问题可以拆成两部分.因为Docker并不是什么完全独创的技术,而是属于很早便有了的容器技术,所以第一个问题就是容器与虚拟机的区别?同属 ...
- HUD:3746-Cyclic Nacklace(补齐循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 其它- in-place
in-place 刷编程题的时候,经常遇到题目要求do in-place.所以就上网搜了相关概念,简单总结一下. in-place操作,意思是所有的操作都是”就地“操作,不允许进行移动,或者称作 ...
- python上数据存储 .h5格式或者h5py
最近在做城市计算的项目,数据文件是以.h5的格式存储的,总结下其用法和特点 来自百度百科的简介: HDF(Hierarchical Data Format),可以存储不同类型的图像和数码数据的文件格式 ...
- 洛谷P1424小鱼的航程改进版
题目链接https://www.luogu.org/problemnew/show/P1424
- 【Reverse Nodes in k-Group】cpp
题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...
- 使用 SceneLoader 类在 XNA 中显示载入屏幕(十)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- android adb常用指令
介绍一个更详细的介绍ADB的: https://github.com/mzlogin/awesome-adb/blob/master/README.md ----------------------- ...
- Locust性能测试框架学习
1. Locust简介 Locust是使用Python语言编写实现的开源性能测试工具,简洁.轻量.高效,并发机制基于gevent协程,可以实现单机模拟生成较高的并发压力. 官网:https://loc ...
- 精通CSS高级Web标准解决方案(3-1 背景图像与图像替换)
3.1背景图像基础 3.2图像替换 使用文本的图像并保留文本的方法.