fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. long long getNextTerm(long long n)
  7. {
  8. if(n%2 == 0) return n/2;
  9. else return 3*n+1;
  10. }
  11.  
  12. vector<int>cache(1000000, 0);
  13.  
  14. int getLength(long long n)
  15. {
  16. if(n >= 1000000) return getLength(getNextTerm(n))+1;
  17.  
  18. if(cache[n] == 0) cache[n] = getLength(getNextTerm(n))+1;
  19. return cache[n];
  20. }
  21.  
  22. int main()
  23. {
  24. cache[1] = 1;
  25. for(int i = 1; i < 1000000; i++) getLength(i);
  26.  
  27. int i, j; while(cin >> i >> j) {
  28. cout << i << ' ' << j << ' '
  29. << *max_element(cache.begin()+min(i, j), cache.begin()+max(i, j))
  30. << '\n';
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.02s 6512KB
stdin
1 10
100 200
201 210
900 1000
stdout
1 10 20
100 200 125
201 210 89
900 1000 174