We are provided with a number N. Our task is to generate all the Hailstone Numbers from N and find the number of steps taken by N to reduce to 1.
Collatz Conjecture: A problem posed by L. Collatz in 1937, also called the 3x+1 mapping, 3n+1 problem. Let N be a integer. According to Collatz conjecture, if we keep iterating N as following
N = N / 2 // For Even N
and N = 3 * N + 1 // For Odd N
the result of N will eventually converge to 1 irrespective of the choice of N
There have an example below :
Input : N = 7
Output :
Hailstone Numbers: 7, 22, 11, 34, 17,
52, 26, 13, 40, 20,
10, 5, 16, 8, 4, 2,
1
No. of steps Required: 17
Hint:
int n;
while(scanf("%d", &n) != EOF){
// your implement code
}
N_1
N_2
...
N_i the input number ( 2 <= N_i < 10^4)
Output Hailstone Numbers (the seqence generated by Collatz conjecture)
(each element sperates with one space and make sure there is a trailing space followed by a newline character at the end of each line.)