#include<bits/stdc++.h>
#define mx7 20000100
using namespace std;
typedef long long LL;
template<class T> T diff(T a,T b) {return a-b<0?b-a:a-b;}
LL ar[mx7+9];
void isStep()
{
ar[0] = 0;
ar[1] = 1;
ar[2] = 2;
for(LL i=3;i<=mx7;i++)
{
LL x = i;
if(x&1)
{
x/=2;
x++;
}
else
{
x/=2;
}
ar[i] = ar[i-1] + x;
}
//for(LL i=1;i<=20;i++)cout << ar[i] << " ";
}
//LL b_srch(LL lo, LL hi, LL item)
//{
// if(lo >= hi)
// {
// return -1;
// }
//
// LL mid = (lo + hi) / 2;
//
// if(ar[mid] == item)
// {
// return mid;
// }
//
// if(ar[mid] > item)
// {
// return b_srch(lo,mid-1,item);
// }
// else
// {
// return b_srch(mid+1,hi,item);
// }
//}
// Binary Search based on the returnable index
LL b_srch(LL target)
{
LL lo=0,hi=mx7,mid;
while(lo <= hi)
{
mid = lo + (hi - lo) / 2;
if(ar[mid] == target)
{
return mid;
}
else if(ar[mid] <= target)
{
lo = mid+1;
}
else
{
hi = mid-1;
}
}
return lo;
}
int main()
{
isStep();
int t;
cin >> t;
while(t--)
{
LL a,b;
cin >> a >> b;
LL d = diff(a,b);
LL res = b_srch(d);
cout << res << endl;
}
return 0;
}
Comments
Post a Comment