#K79022. Minimum Potions to Defeat the Dragon
Minimum Potions to Defeat the Dragon
Minimum Potions to Defeat the Dragon
You are given a dragon with an initial health \(H\) and a potion with potency \(X\). There are two types of potions available:
- Type A: Halve the dragon's health (using floor division), i.e. update \(H\) to \(\lfloor \frac{H}{2} \rfloor\).
- Type B: Subtract \(X\) from the dragon's health, i.e. update \(H\) to \(H - X\).
Your task is to determine the minimum number of potions required to reduce the dragon's health to 0 or below. The optimal strategy at each step is to choose the operation which reduces \(H\) more effectively. In this problem, a greedy strategy is applied: if \(\lfloor \frac{H}{2} \rfloor < H - X\) then applying the halving potion is considered more beneficial; otherwise, use the subtraction potion.
inputFormat
The input consists of a single line containing two integers \(H\) and \(X\) separated by a space:
- \(H\) (\(1 \leq H \leq 10^9\)): the initial health of the dragon.
- \(X\) (\(1 \leq X \leq 10^9\)): the potency of the subtraction potion.
outputFormat
Output a single integer denoting the minimum number of potions required to reduce the dragon's health to 0 or below.
## sample10 3
3
</p>