Grasshopper
InterviewTime limit1sMemory limit128 MB
The grasshopper crosses width x with the fewest jumps, starting at length s and halving each later jump rounded down, with 1 always allowed.
- Level
Easy3 of 10
- Topics
- Greedy, Simulation, Math
- Solved
- No attempts yet
Problem
A grasshopper wants to get across to the other side of a road. Its first jump can have length , but because it grows tired, every jump after that can be at most half the length of the previous one (the jump length is rounded down to an integer). The grasshopper can, however, always make a jump of length without tiring.
Given the width of the road, find the minimum number of jumps the grasshopper must make to reach the other side.
Input
The first and only line of standard input contains two integers and (), denoting the width of the road and the grasshopper's first jump length, respectively.
Output
Print a single integer on the first line of standard output: the minimum number of jumps the grasshopper needs to reach the other side of the road.