fork download
  1. #include <iostream>
  2. #define NUM 3
  3. #define POW 729
  4. using namespace std;
  5.  
  6. int nearest(int weight) {
  7. for (int i = 1; i < POW; i*=NUM){
  8. if (abs(i - weight) < abs(i*NUM - weight)) {
  9. return i;
  10. }
  11. }
  12. }
  13.  
  14. int main() {
  15. int right_bowl, left_bowl = 0, count = 0;
  16. cin >> right_bowl;
  17. while (right_bowl != left_bowl) {
  18. if (right_bowl > left_bowl) {
  19. left_bowl += nearest(abs(right_bowl - left_bowl));
  20. }
  21. else right_bowl += nearest(abs(right_bowl - left_bowl));
  22. count++;
  23. }
  24. cout << count;
  25. }
Success #stdin #stdout 0s 4696KB
stdin
730
stdout
2