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 has2n - 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 than1018.
Note the number of elements in the output array should not be more than 104. If no answer is possible, print - 1.
InputThe only line of input consists of two space separated integers X andd (1 ≤ X, d ≤ 109).
OutputOutput 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.
Examples10 5
6 5 50 7 15 6 100
4 2
4 10 100 1000 10000
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 withMaximum_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.
构造题
例如样例 10 5
构造一个序列,这个序列中的子序列中极差不超过5的序列是有10个
其实可以写1 1 1 6 6
1 和 6 之间的差大于等于 5;也就是说有1 和 6组成的序列不可能满足条件,这就可以吧问题分离开来了,
长度为n的序列的子序列为 pow(2,n)-1个,1 1 1 有 7 个 6 6 有三个,就满足了10.
#include <stdio.h>
#include <math.h>
int main () {
int a,b;
scanf("%d %d",&a,&b);
int i = 0;
long long int tem = 1;
int count = 0;
long long int num[10000];
while(a) {
i = 0;
while(pow(2,i+1) - 1 <= a) {
i++;
}
for(int j = 0; j < i; j++) {
num[count] = tem;
count++;
}
a = a - (pow(2,i) - 1);
tem += b;
}
printf("%d\n",count);
for(int j = 0 ; j < count ; j++) {
printf("%lld ",num[j]);
}
return 0;
}