Guest User

Untitled

a guest
Feb 3rd, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int b = 0;
  7.     cin >> b;
  8.     int c = 0;
  9.     while (b!=1)
  10.     {
  11.         if ((b + 1) % 3 == 0)
  12.         {
  13.             c += 2;
  14.             b = (b + 1) / 3;
  15.         }
  16.         else if (b % 3 == 0)
  17.         {
  18.             c++;
  19.             b = b / 3;
  20.         }
  21.         else
  22.         {
  23.             c++;
  24.             b--;
  25.         }
  26.     }
  27.     cout << c << endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment