Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n;
- cin >> n;
- vector<int> ans = {n};
- while (__builtin_popcount(n) > 1) {
- n -= (n & -n);
- ans.push_back(n);
- }
- while (n > 1) {
- ans.push_back(n / 2);
- n /= 2;
- }
- cout << ans.size() << "\n";
- for (int i : ans) {
- cout << i << " ";
- }
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment