F. Divisibility
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more.

Let's define  for some set of integers  as the number of pairs ab in , such that:

  • a is strictly less than b;
  • a divides b without a remainder.

You are to find such a set , which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that .

Input

The only line contains two integers n and k .

Output

If there is no answer, print "No".

Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set  you have found, in the second line print m integers — the elements of the set , in any order.

If there are multiple answers, print any of them.

Examples
input

Copy
3 3
output
No
input

Copy
6 6
output
Yes
5
1 2 4 5 6
input

Copy
8 3
output
Yes
4
2 4 5 8
Note

In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .

In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, .

题目大意:在1~n中选任意个数组成一个集合I,定义f(I) = I中的每个数被I中的其它的多少个数整除的和.已知f(I) = k,求I.

分析:全程凭感觉做的一道题......

   令d(i)表示i被1~i-1这些数整除的数的个数,e(i) = Σd(j) (1 ≤ j ≤ i).首先需要猜出一个结论:当e(n) ≥ k时,是肯定有解的. 更近一步,当e(i) ≥ k时,肯定有解,那么就可以把>i的数给丢掉.

   假设e(pos) ≥ k,k变成e(pos) - k,将pos / 2 + 1到pos的d全都加入优先队列中,每次弹出最大的d,如果k≥d,则k -= d,并丢掉这个d对应的i.这是基本做法,为什么只需要pos / 2 + 1到pos的数就可以了呢?

   如果考虑的数≤pos / 2,那么删掉这个数的贡献就不只是d,因为[pos / 2 + 1,pos]中有数是它的倍数,这个不好考虑.那为什么只考虑pos / 2 + 1到pos的数就一定最后能让k变成0呢?整除数m的数的个数是O(m ^ (1/3))的.而>m/2并且<m的质数的个数大约是个,一般后者的数量都比前者大,而质数的贡献是1,所以只删去质数就能满足要求,有极少数的数会出现后者比前者小,由于差的非常小,按照上述方法贪心地删就好了.

   如果不按照d来考虑贡献,可以考虑只删除1~pos的质数,对于质数i,它的贡献是[pos / i],删除当前质数不影响其他质数的贡献,其实和上面的贪心方法差不多.

   我曾经考虑过正向构造,每次考虑添加哪个数进去,但是贡献不好算,而且想不到什么好的策略. 这个方法就是把可能的数摆在你的面前,你要在里面删数,不仅要考虑能否满足要求,并且还要考虑贡献的计算问题. 挺考验数学直觉的.

#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,k,sum[],d[],cur,leftt,vis[],ans;
priority_queue <pair<int,int> >q; int main()
{
scanf("%d%d",&n,&k);
for (int i = ; i <= n; i++)
for (int j = i * ; j <= n; j += i)
d[j]++;
for (int i = ; i <= n; i++)
{
sum[i] = sum[i - ] + d[i];
if (sum[i] >= k)
{
leftt = sum[i] - k;
cur = i;
break;
}
}
if (!cur)
puts("No");
else
{
puts("Yes");
if (leftt == )
{
printf("%d\n",cur);
for (int i = ; i <= cur; i++)
printf("%d ",i);
}
else
{
for (int i = cur / + ; i <= cur; i++)
q.push(make_pair(d[i],i));
while (leftt)
{
pair <int,int> temp = q.top();
q.pop();
if (leftt >= temp.first)
{
leftt -= temp.first;
vis[temp.second] = ;
}
}
for (int i = ; i <= cur; i++)
if (!vis[i])
ans++;
printf("%d\n",ans);
for (int i = ; i <= cur; i++)
if (!vis[i])
printf("%d ",i);
}
} return ;
}

Codeforces 922.F Divisibility的更多相关文章

  1. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  2. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  3. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  4. Codeforces 797 F Mice and Holes

    http://codeforces.com/problemset/problem/797/F F. Mice and Holes time limit per test             1.5 ...

  5. Codeforces 622 F. The Sum of the k-th Powers

    \(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i ...

  6. Codeforces 379 F. New Year Tree

    \(>Codeforces \space 379 F. New Year Tree<\) 题目大意 : 有一棵有 \(4\) 个节点个树,有连边 \((1,2) (1,3) (1,4)\) ...

  7. Codeforces 538 F. A Heap of Heaps

    \(>Codeforces \space 538 F. A Heap of Heaps<\) 题目大意 :给出 \(n\) 个点,编号为 \(1 - n\) ,每个点有点权,将这些点构建成 ...

  8. codeforces 825F F. String Compression dp+kmp找字符串的最小循环节

    /** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: d ...

  9. [codeforces 618 F] Double Knapsack (抽屉原理)

    题目链接:http://codeforces.com/contest/618/problem/F 题目: 题目大意: 有两个大小为 N 的可重集 A, B, 每个元素都在 1 到 N 之间. 分别找出 ...

随机推荐

  1. webstorm报错Unescaped xml character解决方案1

    当idea认为你的书写格式不适合的时候便会报出Unescaped xml character提示,但不影响运行. 若想禁掉这个提示,可以尝试修改文档类型为:<!DOCTYPE html>

  2. 微信小程序禁止下拉_解决小程序下拉出现空白的情况

    微信小程序禁止下拉 在微信小程序中,用力往下拉动,页面顶部会出现一段空白的地方. 产品的需求不太允许这么做,会影响用户体验,查看文档发现可以使用enablePullDownRefresh这属性来实现, ...

  3. html5中的progress兼容ie,制作进度条样式

    html5新增的progress标签用处很大,它可以制作进度条,不用像以前那样用css来制作进度条! 一.progress使用方法 progress标签很好使用,他有两个属性,value和max,va ...

  4. C语言函数篇(三)函数参数高级设计

    在内存空间中, 1. 单位大小的数据 叫 数值 . 比如 int a; char b; ... 2. 由这些单位数据组合起来的内存, 称作 空间. 比如: 各种数组char/int a[10]; 结构 ...

  5. Postgres常用命令之增、删、改、查

    增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...

  6. C++ 二叉搜索树

    二叉搜索树利用其特有的二叉树性质,使其搜索更方便 源代码: struct node { int val; node *left, *right; }; //the function of insert ...

  7. 03,Python网络爬虫第一弹《Python网络爬虫相关基础概念》

    爬虫介绍 引入 为什么要学习爬虫,学习爬虫能够为我们以后的发展带来那些好处?其实学习爬虫的原因和为我们以后发展带来的好处都是显而易见的,无论是从实际的应用还是从就业上. 我们都知道,当前我们所处的时代 ...

  8. 1008: [HNOI2008]越狱(计数问题)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 11361  Solved: 4914[Submit][Status ...

  9. miniui IE对省略号即text-overflow:ellipsis显示不一样的问题

    做miniui项目中发现,IE对文本以英文或数字结尾的是英文的省略号,以汉字结尾的就是中文的省略号.只要将字体变为统一宋体即可解决.即 .mini-grid-cell-inner    {       ...

  10. 《Cracking the Coding Interview》——第6章:智力题——题目4

    2014-03-20 01:02 题目:无力描述的一道智力题,真是货真价实的智力题,让我充分怀疑自己智力的智力题.有兴趣的还是看书去吧. 解法:能把题目看懂,你就完成80%了,用反证法吧. 代码: / ...