Josif_tepe

Untitled

Feb 18th, 2026
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5. const long long MOD = 1e9 + 7;
  6. int n;
  7. string to_binary(int x) {
  8.     string res = "";
  9.     while(x > 0) {
  10.         res += (x % 2) + '0';
  11.         x /= 2;
  12.     }
  13.     while((int) res.length() < n) {
  14.         res += "0";
  15.     }
  16.     reverse(res.begin(), res.end());
  17.     return res;
  18. }
  19. int main() {
  20.    
  21.     cin >> n;
  22.    
  23.     int power_of_2 = (1 << n);
  24.     for(int i = 0; i < power_of_2; i++) {
  25.         string s = to_binary(i);
  26.        
  27.         for(int j = 0; j < s.length(); j++) {
  28.             if(s[j] == '1') {
  29.                 cout << j + 1 << " ";
  30.             }
  31.         }
  32.         cout << endl;
  33.     }
  34.    
  35.    
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment