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$ 子序列的字符串. 题解 如下表: ...
随机推荐
- eeeeeeeeeee
http://58.241.123.38/hot.cdn.baidupcs.com/file/91623e76f776475da9c3223cdac861f0?xcode=68983c005f6e3c ...
- 源码级强力分析hadoop的RPC机制
分析对象: hadoop版本:hadoop 0.20.203.0 必备技术点: 1. 动态代理(参考 :http://weixiaolu.iteye.com/blog/1477774 )2. Java ...
- Hive 分析函数lead、lag实例应用
Hive的分析函数又叫窗口函数,在oracle中就有这样的分析函数,主要用来做数据统计分析的. Lag和Lead分析函数可以在同一次查询中取出同一字段的前N行的数据(Lag)和后N行的数据(Lead) ...
- 在MAC下使用Robotframework+Selenium2【第一枪】robotframework安装步骤
最近使用苹果的MAC Pro本本,感受着苹果系统的新鲜,确实让我手忙脚乱一阵,毕竟使用windows系统太长时间了,刚开始用MAC Pro确实感觉别扭,用了一段,发现MAC系统还不错,好了,转入正题. ...
- #3 working with data stored in files && securing your application
This chapter reveals that you can use files and databases together to build PHP application that waa ...
- 5.2 pandas 常用函数清单
文件读取 df = pd.read_csv(path='file.csv') 参数:header=None 用默认列名,0,1,2,3... names=['A', 'B', 'C'...] 自定义列 ...
- HTML练习题
1.查询一下对div和span标签的理解 div标签:是用来为HTML文档内大块的内容提供结构和背景的元素.DIV的起始标签和结束标签之间的所有内容都是用来构成这个块的,中文我们把它称作“层”. sp ...
- Hyper-V动态迁移中?小心性能损失
动态迁移是虚拟化技术的一个标志,它允许虚拟机在服务器间进行动态迁移.调节负载平衡.性能管理.备灾管理和数据中心维护.Windows Server 2012 R2中的Hyper-V动态迁移默认功能具备相 ...
- Python学习-day11 RabbitMQ Redis
这次文章包含两个内容: 1.RabbitMQ使用 2.Redis基础操作 代码部分为练习笔记和作业 概念部分转自Alex老师 RabbitMQ 安装 http://www.rabbitmq.com/i ...
- jquery使用ajax传内容到asp.net乱码解决【转】
转自:http://www.cnblogs.com/qiantuwuliang/archive/2009/08/02/1537160.html#undefined Jquery强大的功能越来越收到广大 ...