Ankit_132

C

Aug 26th, 2023 (edited)
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll     long long
  5. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  6. #define pb     push_back
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {    
  12.         int n;
  13.         cin >> n;
  14.         vector<int> ans = {n};
  15.         while (__builtin_popcount(n) > 1) {
  16.             n -= (n & -n);
  17.             ans.push_back(n);
  18.         }
  19.         while (n > 1) {
  20.             ans.push_back(n / 2);
  21.             n /= 2;
  22.         }
  23.         cout << ans.size() << "\n";
  24.         for (int i : ans) {
  25.             cout << i << " ";
  26.         }
  27.         cout << "\n";
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment