十进制转二进制
发布日期:2021-09-29 21:09:54 浏览次数:1 分类:技术文章

本文共 2789 字,大约阅读时间需要 9 分钟。

除二取余,逆序排列

偶数余零,奇数为一

下面这个题需要用到二进制,将n分解成二进制,1的总数为m,若m>k则无解,否则,每次尝试将最高位所有的数转化为下一位,这样的话每次最高位个数*2,直到总和超过k,此时已无解,因此倒退一步,即确定了最大的值,然后继续拆最大值,直到m=k,然后贪心放置位置即可

 

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

Yes3 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.

#include
/***************有点棘手**************/int ans[100005],v[100005];int main() { long long n,k; scanf("%lld%lld",&n,&k); int i,index=0,cnt=0;//cnt记录已经拆了多少个 //先拆成2进制 while(n) { if(n%2==1) { v[index]=1; cnt++; } index++; n/=2; } //如果cnt已经大于k,cnt当前记录的是最少要拆几个 if(cnt>k) { printf("No\n"); return 0; } printf("Yes\n"); int minn; //二进制顺序反转 for(i=0; i
=ans[i]) { cnt+=ans[i]; ans[i+1]+=ans[i]*2; ans[i]=0; } else break; if(i+1>minn)minn=i+1; //更新最小值下标 } //从最小值开始拆 for(;; i++) { if(cnt==k)break; cnt++; ans[minn]--; ans[minn+1]+=2; minn++; } //找到输出下标上限 int a=index>i?index-1:i; a=minn>a?minn:a; //输出,末尾可以留空格 for(i=0; i<=a; i++) { while(ans[i]) { ans[i]--; minn=index-i-1; printf("%d ",minn); } } printf("\n"); return 0;}

 

转载地址:https://blog.csdn.net/hou_shiyu/article/details/81449936 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:素数筛选法
下一篇:浅谈getchar

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月26日 04时06分01秒