#C5373. Minimum Steps to Reduce to Zero

    ID: 49015 Type: Default 1000ms 256MiB

Minimum Steps to Reduce to Zero

Minimum Steps to Reduce to Zero

In this problem, you are given a positive integer (n). Your task is to determine the minimum number of operations required to reduce (n) to zero. In each operation, if (n) is even, you divide it by 2 (i.e. (n = \frac{n}{2})); if (n) is odd, you subtract 1 (i.e. (n = n - 1)).

This challenge tests your ability to implement simple conditional logic efficiently. It is both a simulation and a greedy algorithm problem.

inputFormat

The input consists of a single integer (n) ((1 \leq n \leq 10^9)), representing the starting number.

outputFormat

Output a single integer representing the minimum number of steps required to reduce (n) to 0 by applying the following operations:

(\text{if } n \text{ is even, then } n = \frac{n}{2})
(\text{if } n \text{ is odd, then } n = n - 1)## sample

8
4