-
Title Description:
-
For a number n, if it is even, cut off n half, if it is odd, turn N into 3*n+ 1 and cut it down by half until the number becomes 1.
Please calculate how many steps it takes to change N to 1, which is a concrete example.
-
Input:
-
The test consists of multiple use cases, each containing an integer n, which indicates the end of the input when n is 0. (1<=n<=10000)
-
Output:
-
for each set of test cases, output a number that represents the number of steps that need to elapse, one row for each set of outputs.
-
Sample input:
-
310
-
Sample output:
-
50
-
Source:
- 2009 Zhejiang University computer and software engineering research on the real problem of life test
-
-
FAQ:
Problem solving problems? to discuss the topic of the topic please visit: http ://t.jobdu.com/thread-7755-1-1.html
#include <iostream>using namespace Std; int count = 0;void lala (int n) {if (n==1) cout<<0<<endl; else if (n%2==0) {N=N/2; count++; if (n==1) cout<<count<<endl; else Lala (n); } else {n= (3*n+1)/2; count++; if (n==1) cout<<count<<endl; else Lala (n); }} int main () {int k; while (cin>>k&&k!=0) {lala (k); Count = 0; } return 0;} /************************************************************** problem:1031 user:vhreal language:c++ Resul
t:accepted time:10 Ms memory:1520 kb****************************************************************/
Nine degree oj-title 1031:xxx Law