显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int T, m, k, x, d, flag;
vector<int> a, b;
int main()
{
freopen("Sequence.in", "r", stdin);
freopen("Sequence.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--)
{
a.clear();
b.clear();
cin >> m >> k;
x = 0;
for (int i = 0; i < 5; i++)
if (k & (1 << i))
{
a.push_back((1 << (1 << i)) - 1);
x += a.back();
}
d = m - x;
flag = 0;
if (d < 0)
flag = 1;
else if (d >= 2)
{
if (d % 2 == 0)
b = {d / 2, d / 2};
else
b = {1, 2, (d - 3) / 2, (d - 3) / 2};
}
else if (d == 0)
b.clear();
else if (a[0] == 1)
a[0] = 2;
else
flag = -1;
if (flag)
cout << "-1\n";
else
{
cout << a.size() + b.size() << endl;
for (int v : a)
cout << v << " ";
for (int v : b)
cout << v << " ";
cout << endl;
}
}
return 0;
}