# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912264 | TienDungz | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll MOD = 1e9+7;
double eps = 1e-12;
#define fi first
#define se second
#define INF 2e18
#define int long long
int t, n;
int pre[201];
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
cin >> t;
while (t--) {
bool ok = true;
cin >> n;
vector<int> res;
int cnt = 0;
int p = 0;
for (int j = 60; j >= 0; j--) {
int m = 1LL << j;
if (n - m >= 0) {
n -=m;
if (ok) {
ok = false;
for (int i = 1; i <= j; i++) {
res.push_back(2 * i);
}
p = j;
} else {
res.push_back(2 * j + 1);
}
}
}
cout << res.size() << '\n';
for (int i = 0; i < res.size(); i++) {
cout << res[i] << ' ';
}
cout << '\n';
}
}