Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int b = 0;
- cin >> b;
- int c = 0;
- while (b!=1)
- {
- if ((b + 1) % 3 == 0)
- {
- c += 2;
- b = (b + 1) / 3;
- }
- else if (b % 3 == 0)
- {
- c++;
- b = b / 3;
- }
- else
- {
- c++;
- b--;
- }
- }
- cout << c << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment