首页 技术 正文
技术 2022年11月21日
0 收藏 546 点赞 2,414 浏览 1542 个字

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,993
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845