fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int length(int ch) {
  5. int it = 1;
  6. while (ch != 1) {
  7. if (ch % 2 == 1) {
  8. ch = ch * 3 + 1;
  9. }
  10. else {
  11. ch = ch / 2;
  12. }
  13. it++;
  14. }
  15. return it;
  16. }
  17.  
  18. int main() {
  19. int i, j;
  20. while(cin >> i) {
  21. cin >> j;
  22. int it, maxIt = 0;
  23. for (int a = min(i, j); a <= max(i, j); a++) {
  24. it = length(a);
  25. if (it > maxIt) {
  26. maxIt = it;
  27. }
  28. }
  29. cout << i << ' ' << j << ' ' << maxIt << endl;
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 4300KB
stdin
5 25
70 54
38 250
stdout
5 25 24
70 54 113
38 250 128