Steps
Time limit1sMemory limit128 MB
Find the minimum number of steps from x to y when consecutive step lengths differ by at most 1 and the first and last lengths are 1.
- Level
Medium5 of 10
- Topics
- Math, Greedy, Binary search
- Solved
- No attempts yet
Problem
You walk along the integer points of a straight line. Each step's length must be a nonnegative integer, and compared with the length of the immediately preceding step it must be larger by , equal, or smaller by .
What is the minimum number of steps needed to move from coordinate to coordinate ? The length of the first and the last step must be .
Input
The first line contains , the number of test cases. Each of the following test cases is a line with two integers and , satisfying .
Output
For each test case, print on its own line the minimum number of steps needed to move from to .