fork download
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int cycle_length = 0;
  9. int max_cycle = 0;
  10. int n1, n2;
  11. //cin >> n1;
  12. //cin >> n2;
  13. n1 = 1;
  14. n2 = 10;
  15. for(int num = n1; num <= n2; num++)
  16. {
  17. while ( num != 1 )
  18. {
  19. if (num % 2 != 0 )
  20. {
  21. num = (3 * num ) + 1;
  22. }
  23. else
  24. {
  25. num = (num / 2);
  26. }
  27. cycle_length++;
  28. }
  29. cycle_length++;
  30.  
  31. if(cycle_length > max_cycle)
  32. {
  33. max_cycle = cycle_length;
  34. }
  35. }
  36. cout << n1 << " " << n2 << " " << max_cycle;
  37.  
  38. }
  39.  
Time limit exceeded #stdin #stdout 5s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty