Josif_tepe

Untitled

Feb 18th, 2026
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 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.     for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
  24.         for(int i = 0; i < n; i++) {
  25.             if(bitmask & (1 << i)) {
  26.                 cout << i + 1 << " ";
  27.             }
  28.         }
  29.         cout << endl;
  30.     }
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment