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$ 子序列的字符串. 题解 如下表: ...
随机推荐
- 3、python中的字符串
一.前言 字符串是python中重要的数据类型.字符串就是一段文本,在python中用引号来标示. 二.字符串分类 字符串根据使用场景不同,一共分成3类: (1)单引号.双引号创建的单行字符串: 在单 ...
- git---gui使用
1.登陆的命令: git config –global user.email "1455971532@qq.com" git config –global user.name &q ...
- “帮你APP”团队冲刺8
1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...
- virsh命令管理虚拟机
virsh命令管理虚拟机 libvirt有两种控制方式,命令行和图形界面. 1.图形界面:通过执行名virt-manager,启动libvirt的图形界面,在图形界面下可以一步一步的创建虚拟机,管理虚 ...
- IOS开发学习笔记034-UIScrollView-xib实现分页
通过xib实现分页功能的封装 1.首先实现xib UIView 的尺寸为300*130,因为准备的图片为600*260. scrollView属性设置如下: 2.新建一个和xib同名的类 2.1 类方 ...
- Selenium中如何运行 auto.exe 文件
Runtime exe = Runtime.getRuntime(); try{ String str = "D:\\Auto上传文件\\photo.exe"; exe.exec( ...
- 并发编程——多进程——multiprocessing开启进程的方式及其属性(3)
开启进程的两种方式——Process 方式一:函数方法 from multiprocessing import Process import time def task(name): print('% ...
- c#之线程同步--轻量级同步 Interlocked
轻量级同步 Interlock 为什么说它是轻量级呢?因为它仅对整形数据(即int类型,long也行)进行同步. 如果你学过操作系统里面的PV操作(即信号量),那么你对它已经了解了一般.它实现的正是如 ...
- c++ 中pair类模板的用法详解
pair: 头文件:#include<utility> 类模板:template <class T1, class T2> struct pair 参数:T1是第一个值的数据类 ...
- LINUX系统安装MYSQL命令
1.下载安装包 wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz 2. ...