C.Subsequence Counting cf474 [构造]

C. Subsequence Counting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it.

Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence  - Minimum_element_of_subsequence  ≥ d

Pikachu was finally left with X subsequences.

However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018.

Note the number of elements in the output array should not be more than 104. If no answer is possible, print  - 1.

Input

The only line of input consists of two space separated integers X and d (1 ≤ X, d ≤ 109).

Output

Output should consist of two lines.

First line should contain a single integer n (1 ≤ n ≤ 10 000)— the number of integers in the final array.

Second line should consist of n space separated integers — a1, a2, ... , an (1 ≤ ai < 1018).

If there is no answer, print a single integer -1. If there are multiple answers, print any of them.

Examples
input
Copy
10 5
output
6
5 50 7 15 6 100
input
Copy
4 2
output
4
10 100 1000 10000
Note

In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.

Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.


思路:把x进行分解,构造出可满足的 2^k-1个集合,每个集合互不干扰(+d+1),直至x=0

#include<bits/stdc++.h>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;

const int N=1e5+50;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

vector <ll> ans;

int main(void){
    ll x,d;
    cin >>x >> d;
    ll now=1;
    for(int i=31;i>=1;i--){
        while(x>=(1<<i)-1){//显然while次数很少
            for(int j=1;j<=i;j++)   ans.push_back(now);
            x-=(1<<i)-1;
            now+=d+1;
        }
    }
//    cout <<"x="<<x<<endl;
    cout <<  ans.size()<<endl;
    for(int i=0;i<(int)ans.size();++i)
        printf("%lld ",ans[i]);
    return 0;
}
/**************

**************/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值