UVA 846

#include<iostream>
using namespace std;
int main()
{
    int sum;
    cin>>sum;
    while(sum--)
    {
        int m,n,i;
        cin>>m>>n;
        int dis=n-m;
        if(dis==0)
            cout<<"0"<<endl;
        else
        {
            for(i=0;;i++)
            {
                if(dis==i*i)
                {
                    cout<<2*i-1<<endl;
                    break;
                }
                else if(dis>i*i&&dis<(i+1)*(i+1))
                {
                    if(dis<=i*(i+1))
                    {
                        cout<<2*i<<endl;
                        break;
                    }
                    else
                    {
                        cout<<2*i+1<<endl;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

 

posted @ 2012-04-28 12:09  open your eyes  阅读(141)  评论(0编辑  收藏  举报