fork(6) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int t,s;
  6. int funkcja( int s, int z);
  7.  
  8. int main()
  9. {
  10. cin >> t;
  11.  
  12. for(int i=0;i<t;i++)
  13. {
  14.  
  15. cin >> s;
  16. if (s!=0)
  17. {
  18. int z=0;
  19. cout << funkcja(s,z);
  20. }
  21. else return 0;
  22. }
  23. return 0;
  24. }
  25.  
  26. int funkcja( int s, int z)
  27. {
  28. if (s==1) return z;
  29. else if (s%2==0) return funkcja(0.5*s, z=z+1);
  30. else return funkcja(3*s+1, z=z+1);
  31. }
  32.  
Success #stdin #stdout 0s 15240KB
stdin
5
1 
2
8
3
567
stdout
013761