SamsungOA #2
Reach The Point
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & Math
Start from (0,0) with initial strength K=1. One operation either increases x by K, increases y by K, or increases K by 1. Find the minimum number of operations to reach exactly (a,b); each test case is independent.
Input
The first line contains t, followed by t lines of a b. Full original bounds: 1≤t≤1000, 1≤a,b≤10^9.
Output
For each test case, output one line with the minimum number of operations, t lines in total.
Example 1
Input:
1
1 6
Output:
5
Example 2
Input:
1
1 1
Output:
2
Example 3
Input:
2
2 3
6 6
Output:
4
6
Example notes
The outputs of the three public examples are, in order: 5; 2; 4 / 6. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…