思路:长度为n的严格递增序列有2^n个(包括空序列),[2, 3, 4] 有2^3个, 考虑如何在此基础上添加元素,使得数量再加上2^2, 结论是在2,3之间加个1, 即[2, 1, 3, 4],[2, 3, 4]有2^3个,[3, 4]有2^2个,但是有和[2, 3, 4]重复的,在每个[3, 4]的子序列前面加个1就不会重复了,所有[2, 1, 3, 4]有2^3 + 2^2 个
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, maxm = 2e3 + 5;
int a[maxn], b[maxn];
int n, m;
// int sum[maxn], ans[maxn];
void solve()
{
cin >> n;
int x = n;
int cur = 2;
bool flag = 0;
int pos = 0;
for(int j = 62; j >= 0; j--){
if(x >> j & 1){
pos = j;
break;
}
}
pos--;
int cnt = 2;
vector<int> ans;
for(int j = pos; j >= 0; j--){
if((x >> j) & 1){
ans.pb(cur);
ans.pb(1);
}
else{
ans.pb(cur);
}
cur++;
}
cout << ans.size() << '\n';
for(auto u : ans){
cout << u << ' ';
}
cout << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
}