CF922F Divisibility
题目链接: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的更多相关文章
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 周赛-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 ...
- 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/ ...
- Divisibility by Eight (数学)
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Divisibility
Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...
- HDU 3335 Divisibility (DLX)
Divisibility Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- light oj 1078 - Integer Divisibility
1078 - Integer Divisibility PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
随机推荐
- 【集群实战】Rsync数据同步工具
1. Rsync介绍 1.1 什么是Rsync? Rsync是一款开源的,快速的,多功能的,可实现全量及增量的本地或远程数据同步备份的优秀工具.Rsync软件适用于unix/linux/windows ...
- MySQL根据业务场景归纳常用SQL语句
素材表数据:user[{"id":1,"name":"x"},{"id":2,"name":&quo ...
- idea jdk版本切换
为什么80%的码农都做不了架构师?>>> 打开file-peoject structure,或者 改完project后,点击models里面的sources 和dependenc ...
- Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation
n students are taking an exam. The highest possible score at this exam is m. Let ai be the score of ...
- 数学--数论--HDU1792A New Change Problem(GCD规律推导)
A New Change Problem Problem Description Now given two kinds of coins A and B,which satisfy that GCD ...
- MySQL 增删改查(单表)
1.sql 新增语句 表中插入数据 insert into + 表名 values(字段1value1,字段2value1,字段3value1),(字段1value2,字段2value2,字段3val ...
- 虚拟机上图片服务器搭建(FastDFS+nginx)
文件服务器 0.提前建好需要的文件夹(/home/fastdfs) /home/fastdfs/tracker /home/fastdfs/storage /home/fastdfs/storage/ ...
- Java 常用API(一)
目录 Java 常用API(一) 1. Scanner类 引用类型的一般使用步骤 Scanner的使用步骤 例题 2. 匿名对象 概述 匿名对象作为方法的参数 匿名对象作为方法的返回值 3. Rand ...
- spring学习笔记(二)spring中的事件及多线程
我们知道,在实际开发中为了解耦,或者提高用户体验,都会采用到异步的方式.这里举个简单的例子,在用户注册的sh时候,一般我们都会要求手机验证码验证,邮箱验证,而这都依赖于第三方.这种情况下,我们一般会通 ...
- springmvc与struts2执行流程比较
之前写过一篇struts2的执行流程的文章了,这里对struts2的流程就不做过多的分析,这篇文章主要分析spring-mvc的执行流程以 及struts2与spring-mvc的差别. 1.stru ...