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. html5 手写的canvas实现

    试用支持canvas的浏览器,无JS依赖,运用新的HTML5技术DrawBoard.renderDrawer('myHandWrite',{  penColor:'#FF0000',  penWidt ...

  2. jsp和servlet的区别联系

    jsp和servlet的区别联系 简单的说,SUN首先发展出SERVLET,其功能比较强劲,体系设计也很先进,只是,它输出HTML语句还是采用了老的CGI方式,是一句一句输出,所以,编写和修改HTML ...

  3. 深度学习在gilt应用——用图像相似性搜索引擎来商品推荐和服务属性分类

    机器学习起源于神经网络,而深度学习是机器学习的一个快速发展的子领域.最近的一些算法的进步和GPU并行计算的使用,使得基于深度学习的算法可以在围棋和其他的一些实际应用里取得很好的成绩. 时尚产业是深度学 ...

  4. linux cpu占用100%排查

    某服务器上部署了若干tomcat实例,即若干垂直切分的Java站点服务,以及若干Java微服务,突然收到运维的CPU异常告警. 问:如何定位是哪个服务进程导致CPU过载,哪个线程导致CPU过载,哪段代 ...

  5. dynamic 作为参数传入另一个程序集,获取值

    dynamicOBJ.GetType().GetProperty("key").GetValue(dynamicOBJ, null)

  6. Python 2.7数据类型操作_20161010

    为兼容python3.x版本 print 后都加了括号 python 数据类型 参考廖雪峰大神python2.7教程 http://www.liaoxuefeng.com/wiki/001374738 ...

  7. LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List

    原题链接在这里:https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/ 题目: C ...

  8. 创建maven多模块项目

    一:创建父项目

  9. Codefroces 762A k-th divisor 数论

    Codeforces 762A 题目大意: 给定两个正整数n,k\((n \le 10^{15},k\leq10^9)\),求n的从小到大的第k个约数,无解输出-1 分析: 我们会自然而然地想到找出n ...

  10. python爬虫知识点总结(三)urllib库详解

    一.什么是Urllib? 官方学习文档:https://docs.python.org/3/library/urllib.html 廖雪峰的网站:https://www.liaoxuefeng.com ...