fork download
  1. #include <iostream>
  2. using namespace std;
  3. int func(int n){
  4. if (n==1)return 0;
  5. return func((n%2==0)?n/2:n*3+1)+1;
  6. }
  7. int main() {
  8. int n;
  9. while(cin>>n){
  10. cout<<func(n)<<"\n";
  11. }
  12. }
Success #stdin #stdout 0.01s 5280KB
stdin
3 5 7 8 6
stdout
7
5
16
3
8