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

 #include <bits/stdc++.h>

 using namespace std;

 typedef long long ll;
typedef pair<ll,int> P;
const int maxn = 3e5+;
P have[maxn];
bool cut[maxn];
bool cmp(const P &a,const P &b){
return a.first>b.first;
}
int main(){
int n;
ll k,cnt=;
scanf("%d%lld",&n,&k);
for(int i=;i<=n;i++) have[i].first=,have[i].second=i;
int m;
for(m=;m<=n;m++){
for(int j=m*;j<=n;j+=m) have[j].first++;
cnt+=have[m].first; if(cnt>=k) break;
}
if(cnt<k) return *printf("No\n");
sort(have+,have+m,cmp);
int temp=m;
for(int i=;i<=m;i++){
if(have[i].second>m/&&cnt-have[i].first>=k){
cnt-=have[i].first;
cut[have[i].second]=true;
temp--;
}
if(cnt==k) break;
}
printf("Yes\n");
printf("%d\n",temp);
for(int i=;i<=m;i++){
if(!cut[i]) printf("%d ",i);
}
printf("\n");
return ;
}

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. CF1092 --- Tree with Maximum Cost

    CF1324 --- Maximum White Subtree 题干 You are given a tree consisting exactly of \(n\) vertices. Tree ...

  2. 比特大陆发布终端 AI 芯片 端云联手聚焦安防

    雷帝网 乐天 10月17日报道 比特大陆今日正式发布终端人工智能芯片BM1880,一同发布的还有基于云端人工智能芯片 BM1682 的算丰智能服务器 SA3.嵌入式AI迷你机 SE3.3D 人脸识别智 ...

  3. Unity碰撞检测

    2019独角兽企业重金招聘Python工程师标准>>> 我们在用unity做开发的时候,会遇到要用到碰撞检测的问题,比如说,物体撞到墙壁,子弹打到物体等等,所以这里简单介绍一下uni ...

  4. 基于opencv的人脸识别程序

    1. 解析opencv自带人脸识别源码(……/opencv-3.1.0/samples/cpp/facedetect.cpp) @ 操作系统:Ubuntu 15.04 OpenCV版本:3.1.0 # ...

  5. 2019 ICPC 南京网络赛 H-Holy Grail

    As the current heir of a wizarding family with a long history,unfortunately, you find yourself force ...

  6. 图论--Floyd总结

    Key word:     ①最短路     ②传递闭包:大小关系 数值关系 先后关系 联通关系     ③floyd变形     ④实现方式:插点发法     ⑤思想:动态规划 1.最短路: 最短路 ...

  7. 一个简单的wed服务器SHTTPD(1)————命令行和文件配置解析

    开始学习<LInux网络编程>中的综合案例,虽然代码书上有,还是自己打一下加深理解和印象. 主要有两个函数,完成命令行的解析,另一个实现配置文件的解析,注释还是比较丰富的哦. //star ...

  8. MySQL命令2

    索引与外键 // 添加索引 ALTER TABLE orders ADD KEY order_ix_custid(cust_id); // 删除索引 ALTER TABLE orders DROP K ...

  9. 进程间通信之socketpair

    socketpair是进程间通信的一种方式. API: ]); DEMO: #include <stdio.h> #include <stdlib.h> #include &l ...

  10. 数位dp (2)

    今天继续写几个数位dp F - Balanced Number 题目大意:给你一个区间,让你求这个区间之中满足条件的数字有多少. 这个条件:可以选数的一个位为轴,左右到轴的长度乘上那个数字本身相等的数 ...