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