fork download
  1. #include <stdio.h>
  2. #include<math.h>
  3.  
  4.  
  5. int check(int m)
  6. {
  7. int n = m;
  8. int count=1;
  9. while(n>=1)
  10. {
  11. if(n==1)
  12. {
  13. break;
  14. }
  15. else if(n!=1 && n%2!=0)
  16. {
  17. n = (3*n)+1;
  18. }
  19. else
  20. {
  21. n/=2;
  22.  
  23. }
  24. count++;
  25. }
  26. return count;
  27. }
  28.  
  29.  
  30.  
  31. int main() {
  32. int i,j;
  33. while(scanf("%d %d",&i,&j) != EOF)
  34. {
  35. int max=0;
  36. if(i<=j)
  37. {
  38. int start = i;
  39. while(start<=j)
  40. {
  41. int ans = check(start);
  42. if(ans>=max)
  43. {
  44. max = ans;
  45. }
  46. start++;
  47. }
  48. printf("%d %d %d\n",i,j,max);
  49. }
  50. else
  51. {
  52. int start= i;
  53. while(start>=j)
  54. {
  55. int ans = check(start);
  56. if(ans>=max)
  57. {
  58. max = ans;
  59. }
  60. start--;
  61. }
  62. printf("%d %d %d\n",i,j,max);
  63. }
  64.  
  65. }
  66.  
  67.  
  68. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty