-
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
1#include <cstdio>2#include <cstdlib>3 4 intMainintargcChar Const*argv[])5 {6 intN;7scanf"%d",&n);8 while(n! =0) {9 intAns =0;Ten while(n! =1) { One if(n%2==0) { An = n/2; - } - Else { then =3* n +1; -n = n/2; - } -ans++; + } -printf"%d\n", ans); +scanf"%d",&N); A } at return 0; -}
-
Title Description:
-
when n is 3 o'clock, we get a sequence in the process of validating XXX's Law, 3,5,8,4,2,1, 3 is called the key number, 5,8,4,2 is called the cover number. Now enter n number A[i], according to the theory of the key number and the number of overlays, we just need to verify that some of the numbers can be determined to meet the XXX law, output input n number of the key number. If there are multiple key numbers, they are output in reverse order of their input.
-
Input:
The
-
input data contains multiple use cases, each of which contains an integer n, followed by a row of n integers a[i], where: 1<=n<=500, 1<a[i]<=1000
-
Output:
-
calculate and output the key numbers contained in array A and output in reverse order of their input sequence, one row for each case output.
-
Sample input:
-
33 8 453 8 4 7 1553 8 4 15 70
-
Sample output:
-
315 7 37) 15 3
Nine degrees OJ title 1031:xxx Law Topic 1033: Continue XXX Law