CF916B

B. Jamie and Binary Sequence (changed after round)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:

Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.

To be more clear, consider all integer sequence with length k (a1, a2, ..., ak) with . Give a value  to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.

For definitions of powers and lexicographical order see notes.

Input

The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.

Output

Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.

It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].

Examples
input
23 5
output
Yes
3 3 2 1 0
input
13 2
output
No
input
1 2
output
Yes
-1 -1
Note

Sample 1:

23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23

Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.

Answers like (4, 1, 1, 1, 0) do not have the minimum y value.

Sample 2:

It can be shown there does not exist a sequence with length 2.

Sample 3:

Powers of 2:

If x > 0, then 2x = 2·2·2·...·2 (x times).

If x = 0, then 2x = 1.

If x < 0, then .

Lexicographical order:

Given two different sequences of the same length, (a1, a2, ... , ak) and (b1, b2, ... , bk), the first one is smaller than the second one for the lexicographical order, if and only if ai < bi, for the first i where ai and bi differ.

题意:

就是把一个数分解成一些2的ki次方,(i=1,2,3....),可以重复,要求最大的ki要尽可能的小,但是要求字典序最大,不超过k个,输出这些次方数

主要想明白字典序最小时是什么情况,就能解出来了。

先把n转成二进制形式,统计其含1的个数sum,每个1代表一个2的ki次方。

如果sum>k,就直接输出No,因为无法通过合并不同次的2的ki次方来得到一个2的ki次方

因为最大的次方一定要尽可能小,所以可以利用2^k=2*^(k-1),通过增加组成n的k的个数来减少ki的值,但是转换的时候要注意,

如果sum加上最高为个数大于k,就不要转化了,因为因为转化后字典序亏损大于转化最低位的。举个例子

n=35,k=11

35

的二进制100011

sum=3;

32可以转化为两个16

依此类推

4 4 4 4 4 4 4 4 2 1

sum=10

如果继续转化

好好想想,在

4 4 4 4 4 4 4 4 2 1

的基础上把ki转化为2*k(i-1),不过以下几种情况

4 4 4 4 4 4 4 3 3 2 1

4 4 4 4 4 4 4 4 1 1 1

4 4 4 4 4 4 4 4 2 -1 -1

可以发现转化最低位的1可以最小的损失字典序,但是要注意到转化后最低位就变了,故一位自能转化一次

而在减少最大次方时,要么全转化,要么全不转化。

 

代码:

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
#include<cstdio>
#include<vector>
#include<functional>
#include<set>
#include<cstring>
using namespace std;
#define ll long long
#define kg " "
int main()
{
ll a;
ll b;
cin>>a>>b;
ll aa=a;
ll bb=b;
while(1){
if(aa>bb){
bb+=b;
}
else if(aa==bb){
cout<<aa<<endl;
return 0;
}
else{
aa+=a;
}
if(aa-bb==1){
cout<<aa<<endl;
return 0;
}
if(bb-aa==1){
cout<<bb<<endl;
return 0;
}
}
return 0;
}

 

 

posted @ 2018-01-23 17:15  DNoSay  阅读(1650)  评论(0编辑  收藏  举报