Advertisement
Josif_tepe

Untitled

Mar 17th, 2024
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     int pow = 1;
  8.     vector<int> tino, nino;
  9.     nino.push_back(n);
  10.     while(n > 0) {
  11.         int ost = n % 3;
  12.  
  13.         if(ost == 0) {
  14.             n /= 3;
  15.         }
  16.         else if(ost == 1) {
  17.             n -= 1;
  18.             n /= 3;
  19.             tino.push_back(pow);
  20.         }
  21.         else {
  22.             n += 1;
  23.             n /= 3;
  24.             nino.push_back(pow);
  25.         }
  26.         pow *= 3;
  27.     }
  28.    sort(tino.begin(), tino.end());
  29.    sort(nino.begin(), nino.end());
  30.  
  31.    for(int x : nino) {
  32.        cout << x << " ";
  33.    }
  34.    
  35.    for(int x : tino) {
  36.        cout << x << " ";
  37.    }
  38.        return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement