A positive integer xx is called a power of two if it can be represented as x=2yx=2y, where yy is a non-negative integer. So, the powers of two are 1,2,4,8,16,…1,2,4,8,16,….

You are given two positive integers nn and kk. Your task is to represent nn as the sumof exactly kk powers of two.

Input

The only line of the input contains two integers nn and kk (1≤n≤1091≤n≤109, 1≤k≤2⋅1051≤k≤2⋅105).

Output

If it is impossible to represent nn as the sum of kk powers of two, print NO.

Otherwise, print YES, and then print kk positive integers b1,b2,…,bkb1,b2,…,bk such that each of bibi is a power of two, and ∑i=1kbi=n∑i=1kbi=n. If there are multiple answers, you may print any of them.

Examples

Input

9 4

Output

YES
1 2 2 4

Input

8 1

Output

YES
8

Input

5 1

Output

NO

Input

3 7

Output

NO

题意:给定一个数,让你用1,2,4,8等2的倍数表示出来,并且要用指定的k个数,输出一种即可。

思路:他需要的最小的位数为这个数本身转化成2进制数,其中1的数量为最小需要的二进制数,最多需要多少,是n个,因为都可以用1来表示,然后大一位的数代替即可,故可以表示的范围为2进制1的个数到n,这是可以表示出来的,可以从1进行累加到满足,也可以从高位拆分,高位拆分在一般情况下可能更快

下面是代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std; long long int a[505];
int m=0;
int tochange(int x) { while(x) {
a[m++]=x%2;
x/=2;
}
}//转成2进制
int main() { int n,k;
scanf("%d%d",&n,&k);
int ans=0;
tochange(n);
for(int t=m-1; t>=0; t--) {
if(a[t]==1) {
ans++;
}
}
if(k<ans||k>n) {
cout<<"NO"<<endl;
}//不满足的情况
else {
cout<<"YES"<<endl;
if(ans==k) {//如果直接等于就不用拆分了
for(int t=0; t<m; t++) {
if(a[t]==1) {
long long int s1=pow(2,t);
printf("%lld ",s1);
}
}
} else {//从高位拆分,高位-1,低位+2,ans+1
int p=m-1;
while(ans!=k) {
while(a[p]>=1) {
a[p]--;
a[p-1]+=2;
ans++;
if(ans==k)
{
break;
}
}
p--;
}//输出
for(int t=m-1; t>=0; t--) {
if(a[t]>=1) {
for(int j=0; j<a[t]; j++) {
long long int s2=pow(2,t);
printf("%lld ",s2);
}
}
}
}
}
return 0;
}

Codeforces Round #529 -C- Powers Of Two(二进制拆分)的更多相关文章

  1. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  2. Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)

    Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...

  3. Codeforces Round #529 (Div. 3) C. Powers Of Two (二进制)

    题意:给你一个数\(n\),问是否能有\(k\)个\(2\)次方的数构成,若满足,输出一种合法的情况. 题解:从高到低枚举二进制的每一位,求出\(n\)的二进制的\(1\)的位置放进优先队列中,因为\ ...

  4. Codeforces Round #529 (Div. 3) C. Powers Of Two(数学????)

    传送门 题意: 给出一个整数 n ,问能否将 n 分解成 k 个数之和,且这 k 个数必须是2的幂. 如果可以,输出"YES",并打印出任意一组解,反之输出"NO&quo ...

  5. Codeforces Round #529 (Div. 3) C. Powers Of Two

    http://codeforces.com/contest/1095/problem/C 题意:给n找出k个2的幂,加起来正好等于n.例如 9,4:9 = 1 + 2 + 2 + 4 思路:首先任何数 ...

  6. CodeForces Round #529 Div.3

    http://codeforces.com/contest/1095 A. Repeating Cipher #include <bits/stdc++.h> using namespac ...

  7. Codeforces Round #529 (Div. 3) 题解

    生病康复中,心情很不好,下午回苏州. 刷了一套题散散心,Div 3,全部是 1 A,感觉比以前慢了好多好多啊. 这几天也整理了一下自己要做的事情,工作上要努力... ... 晚上还是要认认真真背英语的 ...

  8. Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心

    A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...

  9. Codeforces Round #529 (Div. 3) F.Make It Connected

    传送门 题意: 有 n 个顶点,每个顶点有个花费 a[ i ],连接顶点 u,v 需要花费 a[v]+a[u]的代价. 有 m 个特殊边,每条边有三个参数 u,v,w 代表的意思是连接 u,v 的花费 ...

随机推荐

  1. python读取文件后切片

    from itertools import islice with open(“1.txt") as f: for a in islice(f,0,2): print(a)

  2. kvm初体验之八:调整vm的vcpu, memory, disk大小

    假设host上创建的vm的名字为vm1. 1. 查看vm1的domain information [root@tanghuimin thm]# virsh dominfo vm1 Id: 10 Nam ...

  3. Intellij IDEA 14代码错误提示如何调出来

  4. windowService中使用多线程

    windowService中使用多线程 代码 using System;using System.Collections.Generic;using System.Linq;using System. ...

  5. Java企业微信开发_10_未验证域名归属,JS-SDK功能受限

    1.现象: 在企业微信后台填写可信域名后,提示:未验证域名归属,JS-SDK功能受限,如下图: 点击“申请域名校验”后, 注意:域名根目录 当时一直不清楚这个域名根目录在哪里,最后让我给试出来了 2. ...

  6. win7 jenkins 修改主目录

    1.安装tomcat 2.下载Jenkins.war包,把Jenkins.war放在D:\01Install\tomcat\webapps目录下,启动tomcat

  7. Python: scikit-image binary descriptor

    这个用例说明 BRIEF binary description algorithm from skimage import data from skimage import transform as ...

  8. MongoDB4.0.0的安装配置—windows

    一.背景 由于要学习MongoDB,所以就下载了最新的MongoDB 的Community Server版的4.0.0版本.可能是新的版本的缘故,在安装配置上与MongoDB3有许多不同,而且在3中的 ...

  9. python find()用法

    案例: ### 1 ### str = "01213456" if str.find("23"): print "YES!" else: p ...

  10. [hiho1584]Bounce

    题意:找出图中经过一次的格子个数. 解题关键: 组合数学的思想:先找出总的经过格子的次数,然后减去2倍的经过2次的格子个数. 1.总的求法:将长延展,当延展到n倍时,能够恰好到达右边的两个端点,则总格 ...