Let's recall that an increasing subsequence of the array a is a sequence that can be obtained from it by removing some elements without changing the order of the remaining elements, and the remaining elements are strictly increasing (i.e., ab1 < ab2 < ⋯ < abk and b1 < b2 < ⋯ < bk). Note that an empty subsequence is also increasing.
You are given a positive integer X. Your task is to find an array of integers of length at most 200, such that it has exactly X increasing subsequences, or report that there is no such array. If there are several answers, you can print any of them.
If two subsequences consist of the same elements but correspond to different positions in the array, they are considered different (for example, the array [2,2] has two different subsequences equal to [2]).
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
The only line of each test case contains a single integer X (2 ≤ X ≤ 1e18).
Output
For each query, print the answer to it. If it is impossible to find the required array, print -1 on the first line. Otherwise, print a positive integer n on the first line — the length of the array. On the second line, print n integers — the required array itself. If there are several answers, you can print any of them. All elements of the array should be in the range [−1e9;1e9].
Input:
4
2
5
13
37
Expected outout:
4
2
5
13
37
This solution works correct but can u give me a different but similar approach to do this smame thing:
#include
#include
#include
int main() {
int t;
std::cin >> t;
for (int i = 0; i < t; ++i) {
// Initialize variables
std::vector<int> output_answer; // To store the output sequence
int intended_number;
std::cin >> intended_number;
--intended_number; // Decrement by 1
// Generate increasing subsequence
int increasing_subsequence_number = 1;
int index = 0;
while (intended_number >= increasing_subsequence_number) {
intended_number -= increasing_subsequence_number;
increasing_subsequence_number *= 2;
output_answer.push_back(index);
++index;
}
// Generate remaining subsequence
index = 10000;
while (intended_number != 0) {
if (intended_number >= pow(2, index)) {
output_answer.push_back(index);
intended_number -= pow(2, index);
}
--index;
}
// Print the length of the output sequence
std::cout << output_answer.size() << '\n';
// Print the elements of the output sequence
for (int element : output_answer) {
std::cout << element << ' ';
}
std::cout << '\n';
}
return 0;
}