fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int x;
  6. int cnt = 0;
  7.  
  8. int main()
  9. {
  10. ios::sync_with_stdio(false);
  11. cin.tie(NULL);
  12.  
  13. cin >> x;
  14.  
  15. while (true)
  16. {
  17. if (x == 1)
  18. {
  19. break;
  20. }
  21. else if (x % 3 == 0)
  22. {
  23. x /= 3;
  24. cnt++;
  25. }
  26. else if ((x - 1) % 3 == 0)
  27. {
  28. x -= 1;
  29. cnt++;
  30. }
  31. else if (x % 2 == 0)
  32. {
  33. x /= 2;
  34. cnt++;
  35. }
  36. }
  37. cout << cnt;
  38. }
  39.  
  40.  
  41.  
Time limit exceeded #stdin #stdout 5s 5284KB
stdin
5
stdout
Standard output is empty