Consider a non-empty array of positive integers inarr. Identify
and print outarr based on the below logic: For each element in inarr, starting
from the left most element, generate a sequence of numbers such that:
1. Starting number in the sequence is element
2. Next number in the sequence is generated based on the current
number such that:
· if the current number Is even, divide it by 2 to get the next
number in the sequence
·
If the current number is odd,
multiply it by 3 and add 1 to get the next number in the sequence
·
Repeat the above steps and keep
generating the numbers until the number 1 is generated
Identify the count of numbers for each of the sequences generated in
the order of occurrence of elements in inarr, add the corresponding identified
counts to outarr
Note: Each sequence will always reach 1 in finite number of steps
Input format: First line contains the elements of Mart' separated
by " "(space)
Read the input from standard input stream.
Output format: Print outarr with the elements separated by to the
standard output stream
Example:
Input : 10 100
Output: 7 26
0 Comments
Post a Comment