100


SUBMITTED BY: Guest

DATE: Dec. 25, 2013, 2:57 p.m.

FORMAT: C++

SIZE: 792 Bytes

HITS: 2038

  1. #include <cstdio>
  2. int main()
  3. {
  4. bool swapped;
  5. unsigned val, min, max, counter, maxcounter;
  6. while ( scanf("%u %u", &min, &max) == 2 )
  7. {
  8. swapped = false;
  9. if (min > max)
  10. {
  11. swapped = true;
  12. unsigned tmp = min;
  13. min = max;
  14. max = tmp;
  15. }
  16. maxcounter = 1;
  17. for ( unsigned i = min; i <= max; ++i )
  18. {
  19. for ( counter = 1, val = i; val != 1; ++counter )
  20. {
  21. if ( val & 1 )
  22. val = 3 * val + 1;
  23. else
  24. val >>= 1;
  25. }
  26. if ( counter > maxcounter )
  27. maxcounter = counter;
  28. }
  29. if ( !swapped )
  30. printf("%u %u %u\n", min, max, maxcounter);
  31. else
  32. printf("%u %u %u\n", max, min, maxcounter);
  33. }
  34. return 0;
  35. }

comments powered by Disqus