CF1095C.Powers Of Two

普及/提高-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

正整数 xx 被称为 2 的幂,当且仅当它可以表示为 x=2yx = 2^y,其中 yy 是一个非负整数。因此,2 的幂为 1,2,4,8,16,…1, 2, 4, 8, 16, \dots。

给定两个正整数 nn 和 kk。你的任务是将 nn 表示为恰好 kk 个 2 的幂之和。

输入格式

The only line of the input contains two integers nn and kk (1≤n≤1091 \le n \le 10^9, 1≤k≤2⋅1051 \le k \le 2 \cdot 10^5).

输入仅包含一行,其中有两个整数 nn 和 kk(1≤n≤1091 \le n \le 10^9,1≤k≤2⋅1051 \le k \le 2 \cdot 10^5)。

输出格式

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,…,bkb_1, b_2, \dots, b_k such that each of bib_i is a power of two, and ∑i=1kbi=n\sum \limits_{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.

如果无法将 nn 表示为 kk 个 2 的幂之和,则输出 NO。

否则,输出 YES,然后输出 kk 个正整数 b1,b2,…,bkb_1, b_2, \dots, b_k,使得每个 bib_i 均为 2 的幂,且 ∑i=1kbi=n\sum \limits_{i = 1}^{k} b_i = n。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    9 4

    输出#1

    YES
    1 2 2 4
  • 输入#2

    8 1

    输出#2

    YES
    8
  • 输入#3

    5 1

    输出#3

    NO
  • 输入#4

    3 7

    输出#4

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页