Advertisement
Georgiy1108

Untitled

Nov 24th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. main(){
  7.     ios::sync_with_stdio(false);
  8.     cin.tie(0);
  9.     vector<long long> st(62);
  10.     st[0] = 1;
  11.     for(int i = 1; i < 62; i++) st[i] = st[i-1]*2;
  12.    
  13.    
  14.     long long len,k;
  15.     cin>>len>>k;
  16.    
  17.     long long mx = st[len]-1;
  18.     vector<long long> ans;
  19.     ans.push_back(mx);
  20.     k--;
  21.    
  22.     long long del = 0;
  23.     long long ptr = 0;
  24.     while(k>0){
  25.         long long deleted = 0;
  26.         long long addition = 0;
  27.         while(k>=st[addition]){
  28.             k-=st[addition];
  29.             addition++;
  30.            
  31.             ans.push_back(mx-del-st[ptr]);
  32.             deleted+=st[ptr];
  33.             ptr++;
  34.         }
  35.         del+=deleted;
  36.     }
  37.     cout<<ans.size()<<"\n";
  38.     for(auto t:ans) cout<<t<<" ";
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement