A random number generator is as per logic below.
Suppose we select some initial number X and then build the sequence of values by the following rules:
if X is even i.e. X modulo 2 = 0) then
Xnext = X / 2
else
Xnext = 3 * X + 1
1.e. if X is odd, sequence grows - and if it is even, sequence decreases.
For example, with X = 15 we have sequence:
15 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1
After the sequence reaches 1 it enters the loop 1 421 421....
The intrigue is in the fact that any starting number X gives the sequence which sooner or later reaches 1.
Your task is for given numbers to calculate how many steps are necessary to come to 1.
Pro
Input data value for which calculations should be performed. Answer the count of steps for getting Sequence to 1.
Input format
A positive integer
Output format
Number of steps required to reach 1
Answers
Answered by
0
Answer:
10
Explanation:
I think this Will help you
Similar questions