fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int getLength(int n)
  6. {
  7. if(n == 1) return 1;
  8. if(n%2 == 0) return getLength(n/2)+1;
  9. else return getLength(3*n+1)+1;
  10. }
  11.  
  12. int main()
  13. {
  14. int i, j; while(cin >> i >> j) {
  15. int currMax = 0;
  16. for(int n = min(i, j); n <= max(i, j); n++)
  17. currMax = max(currMax, getLength(n));
  18. cout << i << ' ' << j << ' ' << currMax << '\n';
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 4504KB
stdin
1 10
100 200
201 210
900 1000
stdout
1 10 20
100 200 125
201 210 89
900 1000 174