显示代码纯文本
#include <cstdio>
#include <vector>
#define lowbit(x) (x & -x)
int T;
int M, K;
::std::vector<int> vec;
int main() {
freopen("Sequence.in", "r", stdin);
freopen("Sequence.out", "w", stdout);
scanf("%d", &T);
while (T--) {
vec.clear();
scanf("%d %d", &M, &K);
for (int i = lowbit(K); K; K -= lowbit(K), i = lowbit(K)) {
vec.push_back((1 << i) - 1);
M -= (1 << i) - 1;
}
if (M < 0) {
printf("-1\n");
continue;
}
if (M & 1) {
if (M == 1) {
if (vec[0] == 1) {
vec[0] = 2;
} else {
printf("-1\n");
continue;
}
} else {
vec.push_back(1);
vec.push_back(2);
M -= 3;
vec.push_back(M / 2);
vec.push_back(M / 2);
}
} else {
vec.push_back(M / 2);
vec.push_back(M / 2);
}
printf("%llu\n", vec.size());
for (auto x : vec) {
printf("%d ", x);
}
printf("\n");
}
return 0;
}