Concider a non-empty array of position integers inarr. Identify and print outarr based onn the below logic:
Note: Each sequence will always reach 1 in finite number of steps
Input format:
First line contains the elements of inarr separated by " "(space).
Read the input from standard input stream. <br />
Output format:
Print outarr with the elements separated by ',' to the standard output stream.
Sample Input | Sample Output |
---|---|
10 100 | 7,26 |
The elements of the given inarr are 10,100.
The sequence generated for each element starting from the left most element of inarr and their corresponding count are:
For 10: Starting number of the sequence is 10. Since 10 is even the 2nd number of the sequence is 10/2=5. Since 5,the 2nd number of the sequence, is odd the 3rd number in the sequence is ((5*3)+1)=16. Similarly by repeating the steps the sequence generated for element 10 is:
10, 5, 16, 8, 4, 2, 1
The count of the numbers in the sequence is 7
For 100: Using Similar rules , The count of the numbers is 26.