A research reactor's core fuel counter starts at an integer value n. Every second, an automated controller inspects the counter: if it is currently even, a fission burn instantly consumes exactly half of the remaining fuel units (the counter is halved); if it is odd, a single unit is bled off for safety (the counter decreases by one). This continues, one operation per second, until the counter reaches zero. Report how many seconds the depletion takes.
A single line containing one integer n.
Print a single integer: the number of seconds until the counter reaches zero.
Example 1
Input
14
Expected
6
Explanation
14(even)->7 [1], 7(odd)->6 [2], 6(even)->3 [3], 3(odd)->2 [4], 2(even)->1 [5], 1(odd)->0 [6]. It takes 6 seconds to reach zero.
Example 2
Input
123
Expected
12
Explanation
123(odd)->122[1], 122->61[2], 61->60[3], 60->30[4], 30->15[5], 15->14[6], 14->7[7], 7->6[8], 6->3[9], 3->2[10], 2->1[11], 1->0[12]. It takes 12 seconds to reach zero.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →