Untitled


SUBMITTED BY: Guest

DATE: Dec. 5, 2013, 3:13 p.m.

FORMAT: Text only

SIZE: 888 Bytes

HITS: 602

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int main ()
  5. {
  6. int i, j, t_i, t_j,s;
  7. while(scanf("%d %d", &i, &j)!=EOF )
  8. {
  9. t_i = i;
  10. t_j = j;
  11. if (i>j )
  12. {
  13. s=i;
  14. i=j;
  15. j=s;
  16. }
  17. int max_length = 0;
  18. int cycle_length;
  19. while(i<=j)
  20. {
  21. int n = i;
  22. cycle_length = 1;
  23. while (n!=1)
  24. {
  25. if ((n%2)==1) n = 3 * n + 1;
  26. else n = (n/2);
  27. cycle_length++;
  28. }
  29. if (cycle_length>max_length)
  30. max_length = cycle_length;
  31. i++;
  32. }
  33. printf ("%d %d %d\n", t_i, t_j, max_length);
  34. }
  35. return 0;
  36. }

comments powered by Disqus