(RankList for this Question)
You are given a positive integer ‘n’. If ‘n’ is even, you divide it by 2 and if ‘n’ is odd, you multiply it by 3 and then add 1. You repeat this, until ‘n’ becomes 1. Your task is to program this simulation for a given ‘n’.
Constraints
\( 1 \leq n \leq 10^{6} \)
Input Format
Input contains the positive integer ‘n’.
Output Format
Print all the values of ‘n’ during the simulation in a single line, separated by spaces
Example 1
Input:
3
Output:
3 10 5 16 8 4 2 1
Explanation:
3 is odd so we multiply it by 3 and then add 1.
10 is even so we divide it by 2 and continue the procedure
Log In to solve the Question