题意:
给你两个数A,B,,你可以一系列操作,这一系列操作是 第一个回合,你必须让A或者B 加上 1 , 第二回合你必须让A或者B加上2, 第三回合你必须要让A或者B加上3…你可以进行任意回合的操作,但是你需要找到最小回合,使得A和B相同。
思路:
可以先预处理从1到10000的前缀和(因为数据范围就知道了1e9,可以保证一定大于等于1e9)
首先如果a,b相等那么直接输出0就好,如果不相等,从第一个开始遍历,如果满足条件:加起来的和为偶数(因为要均分为两个)并且当前的前缀和值大于等于两个数相差的值就直接输出即可。
总共的时间最多也就1e5*1e2=1e7;
代码:
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;
const int N=1000000+100;
int n ,m,h;
ll s[N];
void init()
{
int res=0;
for(int i =1;i<=100000;i++)
{
res+=i;
s[i]=res;
}
}
//1 2 3 4 5 6
//1 3 6 10 15 21 10 21 24
int main()
{
init();
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
if(n==m)cout<<0<<endl;
else{
int i=1;
while((s[i]+n+m)%2!=0||s[i]<(abs(n-m)))i++;
cout<<i<<endl;
}
}
return 0;
}