846

#include <iostream>

#include <math.h>

using namespace std;

//long long diff[10001];
long long int m,n,d;

int main()
{
int t;

cin>>t;
while(t--)
{
cin>>m>>n;
d= m-n;
if(d<0)
d=d*(-1);

if(d==0)
{
cout<<0<<"\n";
continue;
}
if(d==1)
{
cout<<1<<"\n";
continue;
}
if(d==2)
{
cout<<2<<"\n";
continue;
}
if(d==3)
{
cout<<3<<"\n";
continue;
}

long long int r= sqrt(d);
if(r<0)
r*=-1;

if(d==r*r)
{
cout<<2*r-1<<"\n";
continue;
}

long long int x=(r+1)*(r+1)-r*r;

if(d<=(r*r)+x/2)
cout<<2*r<<"\n";
else
cout<<2*r+1<<"\n";
}

return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *