Advertisement
Tahsin24

Untitled

Oct 9th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int count_step(long long int n)
  4. {
  5. long long int c = 1;
  6. while(n != 1)
  7. {
  8. if(n % 2 == 0)
  9. {
  10. n = n / 2;
  11. }
  12. else
  13. {
  14. n = 3 * n + 1;
  15. }
  16. c++;
  17.  
  18. }
  19. return c;
  20.  
  21. }
  22.  
  23. int main()
  24. {
  25. long long int a, b, max, i;
  26.  
  27. while(scanf("%lld %lld", &a, &b) == 2)
  28. {
  29. if(a >= b)
  30. {
  31. max = 0;
  32. for(i = b; i <=a; i++)
  33. {
  34. if(count_step(i) > max)
  35. {
  36. max = count_step(i);
  37. }
  38. }
  39. printf("%lld %lld %lld\n",a, b, max);
  40. }
  41. if(a < b)
  42. {
  43. max = 0;
  44. for(i = a; i < b; i++)
  45. {
  46. if(count_step(i) > max)
  47. {
  48. max = count_step(i);
  49. }
  50. }
  51. printf("%lld %lld %lld\n",a, b, max);
  52. }
  53.  
  54. }
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement