(本文思路完全来源于)starlet_kiss
(color{Red}{----------分割线-------------})
(开始a,b,x=abs(a-b))
(现在要求pm1pm2pm3....pm{n}=x)
(一开始我们一直加直到color{Red}{超过x时停下})
(1+2+3...+n=x+y(刚好超过了x,加到了x+y))
(color{Orange}{Ⅰ.当y为偶数,那么前面有一次frac{y}{2}我们不加,而是减去它,就得到了x})
(这种情况下,只需要操作n次即可(一定最优))
(color{Green}{Ⅱ.y为奇数,此时y不能被2整除})
(那我们就构造出新的y为偶数)
(Ⅱ.1. 当n+1为奇数时)
(1+2+3...+(n+1)=x+y(此时y被构造成了偶数))
(那么这时候需要操作n+1次)
(Ⅱ.2. 当n+1为偶数,那么n+2为奇数)
(1+2+3...+(n+2)=x+y(此时y被构造成了偶数))
(那么此时需要操作n+2次)
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,t;
signed main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
int x=abs(n-m);
int l=0,r=1e6,mid;
while(r>l)
{
mid=(l+r)/2;
if(mid*(mid-1)/2+mid>=x) r=mid;
else l=mid+1;
}
int y=r*(r-1)/2+r-x;
if(y%2==0) cout<<r<<endl;
else if((r+1)%2==1) cout<<r+1<<endl;
else cout<<r+2<<endl;
}
}