rotti321

collatz

Oct 24th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n,k=1;
  8. cin>>n;
  9.  
  10. while(n!=1)
  11. {
  12. if(n%2==0)
  13. n=n/2;
  14. else
  15. n=3*n+1;
  16. k++;
  17. }
  18. cout<<k;
  19. return 0;
  20. }
Add Comment
Please, Sign In to add comment