Codeforces Round #529 (Div. 3) C

C. Powers Of Two

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 sum of 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

Copy

9 4

Output

Copy

YES
1 2 2 4 

Input

Copy

8 1

Output

Copy

YES
8 

Input

Copy

5 1

Output

Copy

NO

Input

Copy

3 7

Output

Copy

NO

思路:

开个大小为k的数组,先把每个都填上1,之后设法把他们的和向n靠近,每次单个乘以2

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int temp = k;
    fill(a,a + k,1);
    for (int i = 0;i < k;i ++)
    {
        while (temp + a[i] <= n)
        {
            temp += a[i];
            a[i] *= 2;
        }
    }
    if (temp != n) puts("NO");
    else
    {
        printf("YES\n%d",a[k - 1]);
        for (int i = k - 2;i >= 0;i --) printf(" %d",a[i]);
        puts("");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值