Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. int fun(int);
  6.  
  7. int main()
  8. {
  9. int i,j;
  10. while (cin >> i >> j)
  11. {
  12. int first = 0, last;
  13. for (int k = min(i,j); k <= max(i,j); k++)
  14. {
  15. last = fun(k);
  16. if (last >= first)
  17. {
  18. first = last;
  19. }
  20. }
  21. cout << i << " " << j << " " << first << endl;
  22. }
  23. }
  24.  
  25. int fun(int k)
  26. {
  27. if (k == 1)
  28. {
  29. return 1;
  30. }
  31. else if (k % 2 == 0)
  32. {
  33. return fun(k/2) + 1;
  34. }
  35. else
  36. {
  37. return fun(3*k+1) + 1;
  38. }
  39. }
Add Comment
Please, Sign In to add comment