main.cpp 703 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int i, j, n = 0;
  5. int cyc = 0, cyc_max = 0;
  6. while(cin >> i >> j)
  7. {
  8. // if(cyc_max)
  9. // cout << endl;
  10. cyc_max = 0;
  11. for(int q = min(i,j); q <= max(i,j); q++)
  12. {
  13. n = q;
  14. cyc = 1;
  15. while (n != 1)
  16. {
  17. if (n%2 == 1) // Om n inte är ett heltal gör ->
  18. n = 3*n+1;
  19. else
  20. n = n/2; // Om n är ett heltal gör ->
  21. cyc++;
  22. }
  23. cyc_max = max(cyc_max, cyc);
  24. }
  25. cout << i << " " << j << " " << cyc_max << endl;
  26. }
  27. return 0;
  28. }