Given two integers A
, where A is the first element of the sequence then find Bth
element of the sequence.
If the kth
element of the sequence is X
element calculated as:
- if X is even then next element is X/2.
- else next element is 3×X + 1.
1 <= A <= 109Input Format
1 <= B <= 105
Given two integers A and B.Output Format
Return an integer.Example Input
A = 1
B = 3
A = 5
B = 6
The sequence is as follows 1 -> 4 -> 2
The sequence is as follows 5 -> 16 -> 8 -> 4 -> 2 -> 1
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified.
Still have a question? Checkout Sample Codes for more details.