-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAandB.cpp
More file actions
executable file
·53 lines (48 loc) · 1.27 KB
/
AandB.cpp
File metadata and controls
executable file
·53 lines (48 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// g++ AandB.cpp -o AandB && ./AandB
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " " << x << endl;
vector<int> arr(1e5, 0);
int lb(int num){
int low = 0, high = 1e5, mid;
while(low <= high){
mid = (low+high)/2;
if(num >= arr[mid] && num < arr[mid+1]){
// deb((num >= arr[mid] && num < arr[mid+1]));
// deb((num >= arr[mid]));
// deb((num < arr[mid+1]));
// deb(arr[mid]);
int ans ;
if(num == arr[mid]) {
ans = mid;
}
else {
ans = mid+1;
}
while(1){
if((arr[ans]+num)%2 == 0) {
// deb(arr[ans]);
// deb(num);
return ans;
}
else ans++;
}
}
else if(num > arr[mid]) low = mid+1;
else high = mid-1;
}
return -1;
}
int main(){
for(int i = 1; i < 1e5; i++) arr[i] = (i + arr[i-1]);
int t;
cin >> t;
while(t--){
int a;
int b;
cin >> a >> b;
int temp = abs(a-b);
//int tans = lb(temp);
cout << lb(temp) << endl;
}
}