#K6726. Number of Steps to Reduce a Number to Zero
Number of Steps to Reduce a Number to Zero
Number of Steps to Reduce a Number to Zero
Given a non-negative integer n
, your task is to determine the minimum number of steps required to reduce n
to zero using the following operations:
- If
n
is even, replace it with \(\frac{n}{2}\). - If
n
is odd, replace it with \(n - 1\).
For example, if n = 14
, the optimal sequence is: 14 \(\to\) 7 \(\to\) 6 \(\to\) 3 \(\to\) 2 \(\to\) 1 \(\to\) 0, taking 6 steps in total.
inputFormat
The input consists of a single non-negative integer n
read from standard input.
Example:
14
outputFormat
Output a single integer representing the minimum number of steps required to reduce n
to zero.
Example:
6## sample
0
0