Advertisement
dmkozyrev

c.cpp

Apr 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef int64_t Int;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.    
  10.     //freopen("input.txt", "rt", stdin);
  11.    
  12.     Int need, diff; cin >> need >> diff;
  13.    
  14.     if (need <= 10000) {
  15.         cout << need << endl;
  16.         for (int i = 0; i < need; ++i) {
  17.             cout << 1 + diff * i << " ";
  18.         }
  19.         return 0;
  20.     }
  21.  
  22.     vector<Int> a;
  23.    
  24.     Int curr = 1;
  25.    
  26.     while (need > 0) {
  27.        
  28.         Int pow = 1;
  29.         while ((Int(1) << (pow+1)) - 1 <= need) {
  30.             ++pow;
  31.         }
  32.        
  33.         need -= ((Int(1) << pow) - 1);
  34.        
  35.         for (Int i = 0; i < pow; ++i) {
  36.             a.push_back(curr);
  37.         }
  38.        
  39.         assert(curr < (Int)1e18L);
  40.        
  41.         curr += diff;
  42.     }
  43.    
  44.     assert(a.size() <= (Int)1e4);
  45.    
  46.     cout << a.size() << endl;
  47.    
  48.     for (auto it : a) cout << it << " ";
  49.    
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement