description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
m = int((abs(b - a) * 2) ** 0.5)
for i in range(10):
q = m * (m + 1) // 2
if q >= abs(b - a) and (q - abs(b - a)) % 2 == 0:
print(m)
break
m += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for i in range(int(input())):
a, b = map(int, input().split())
if a > b:
a, b = b, a
diff = b - a
n = int((1 + 8 * (b - a)) ** 0.5 - 1) // 2
if n * (n + 1) // 2 != diff:
n += 1
while (n * (n + 1) // 2 - diff) % 2 != 0:
n += 1
print(n)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(0, t):
a, b = map(int, input().split())
resta = abs(a - b)
if resta % 2 == 0:
k = int((2 * resta) ** 0.5)
suma = int(k * (k + 1) / 2)
while suma < resta:
k += 1
suma = int(k * (k + 1) / 2)
while suma % 2 != 0:
k += 1
suma = int(k * (k + 1) / 2)
else:
k = int((2 * resta) ** 0.5)
suma = int(k * (k + 1) / 2)
while suma < resta:
k += 1
suma = int(k * (k + 1) / 2)
while suma % 2 != 1:
k += 1
suma = int(k * (k + 1) / 2)
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for i in range(int(input())):
a, b = map(int, input().split())
if a < b:
a, b = b, a
d = a - b
n = (-1 + (1 + 8 * d) ** 0.5) // 2
k = d - (n * n + n) // 2
if k != 0:
n = n + 1
k = (n * n + n) // 2 - d
if k % 2 == 0:
print(round(n))
elif (n + 1) % 2 == 0:
print(round(n + 2))
else:
print(round(n + 1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def main():
for t in range(int(input())):
n, m = map(int, input().split())
if n == m:
print(0)
else:
diff = -1 * abs(n - m)
k = 1
while diff < 0:
diff += k
k += 1
if diff % 2 == 0:
print(k - 1)
else:
diff += k
if diff % 2 == 0:
print(k)
else:
print(k + 1)
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def solve():
t = int(input())
for case in range(t):
a, b = map(int, input().split())
if a > b:
a, b = b, a
a, b = 0, b - a
if b == 2:
print(3)
continue
cur = 0
while a < b:
cur += 1
a += cur
if (a - b) % 2 == 1:
tmp = cur + 1 + a - b
if tmp % 2 == 0 and tmp / 2 <= cur:
cur += 1
else:
cur += 2
print(cur)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def solve():
a, b = map(int, input().split())
if b < a:
a, b = b, a
c = abs(a - b)
low = 0
high = c + 4
while low + 1 < high:
mid = (low + high) // 2
if mid * mid <= c:
low = mid
else:
high = mid
while True:
d = a + low * (low + 1) // 2 - b
if d >= 0 and d % 2 == 0:
break
low += 1
print(low)
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def solve():
a, b = map(int, input().split())
d = abs(a - b)
if d == 0:
print(0)
return
count = 1
while True:
sum = count * (count + 1) / 2
if sum >= d and sum % 2 == d % 2:
break
count += 1
print(count)
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
sums = []
def solve(a, b):
d = abs(a - b)
if d == 0:
return 0
else:
p = d % 2
n = int((2 * d) ** 0.5)
while True:
s = n * (n + 1) // 2
if s % 2 == p and s >= d:
return n
n += 1
t = int(input())
for i in range(t):
a, b = tuple(map(int, input().strip().split()))
print(solve(a, b))
|
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
cum_sum = [0] * 47000
cum_sum[1] = 1
for i in range(2, 47000):
cum_sum[i] = cum_sum[i - 1] + i
n = int(input())
for i in range(n):
a, b = map(int, input().split())
delta = max(a, b) - min(a, b)
cnt = cum_sum.index([el for el in cum_sum if el <= delta][-1])
eq = a + b + cum_sum[cnt]
while eq % 2 != 0 or eq // 2 < max(a, b):
cnt += 1
eq += cnt
print(cnt)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def check(x, sum):
tmp = int(x * (x + 1) / 2)
if tmp < sum:
return False
return tmp % 2 == sum % 2
n = int(input())
for it in range(n):
a, b = map(int, input().split())
sum = abs(a - b)
if sum == 0:
print(0)
continue
x = 1
while not check(x, sum):
x += 1
print(x)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
a, b = max(a, b), min(a, b)
sm = 0
c = 0
while sm < a - b:
c += 1
sm += c
if (b + sm - a) % 2 == 0:
print(c)
elif (c + 1) % 2 == 0:
print(c + 2)
else:
print(c + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
l = []
curr = 0
while 1:
x = curr * (curr + 1) // 2
if x > 10**10:
break
l.append(x)
curr += 1
t = int(input())
for you in range(t):
lo = input().split()
a = int(lo[0])
b = int(lo[1])
diff = max(a, b) - min(a, b)
for i in range(len(l)):
if l[i] >= diff and (l[i] - diff) % 2 == 0:
ans = i
break
print(ans)
|
ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
l = []
for i in range(10**5 + 1):
l.append(i * (i + 1) // 2)
t = int(input())
for i in range(t):
a, b = map(int, input().split())
if a == b:
print(0)
else:
d = abs(a - b)
c = 0
for i in range(len(l)):
u, v = l[i] % 2, d % 2
if l[i] >= d and u == v:
print(c)
break
else:
c += 1
i += 1
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def diff(a, b):
return int(abs(a - b))
def check(a):
if a < 0:
return False
s = str(a)
for x in range(0, len(s)):
if s[x] == ".":
if s[x + 1] == "0":
return True
else:
return False
def value(n):
return int(n * (n + 1) / 2)
def calculate(a, b):
d = diff(a, b)
x = -1
n = 0
while x == -1:
p = (value(n) - d) / 2
if check(p):
return n
else:
x = -1
n = n + 1
l = []
size = int(input())
for k in range(0, size):
m, n = map(str, input().split())
l.append((int(m), int(n)))
for k in l:
print(calculate(k[0], k[1]))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
continue
if a > b:
a, b = b, a
i = 0
while i * (i + 1) // 2 - abs(b - a) < 0 or (i * (i + 1) // 2 - abs(b - a)) % 2 != 0:
i = i + 1
print(i)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
ch = input()
L = [int(i) for i in ch.split()]
a = L[0]
b = L[1]
n = abs(a - b)
i = 0
s = 0
while True:
if s - n >= 0 and (s - n) % 2 == 0:
break
i += 1
s += i
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
while t:
t -= 1
a, b = map(int, input().split())
d = abs(a - b)
r = 0
while r * (r + 1) < 2 * d or ((r + 1) // 2 - d) % 2:
r += 1
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
import sys
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
def compute(start, end):
if start == end:
return 0
t = abs(end)
step = 0
curr = start
while True:
curr += step + 1
if curr >= t:
if (curr - t) % 2 == 0:
return step + 1
step += 1
T = int(input())
while T:
x, y = get_ints()
start = min(x, y)
end = max(x, y)
ans = compute(start, end)
print(ans)
T -= 1
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
let = "@abcdefghijklmnopqrstuvwxyz"
for _ in range(ii()):
a, b = f()
sm = 0
for i in range(10**5 + 1):
sm += i
if (a + b + sm) % 2 == 0 and (a + b + sm) // 2 >= max(a, b):
print(i)
break
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
while t:
t += -1
a, b = [int(x) for x in input().split()]
if a > b:
a, b = b, a
if a == b:
print(0)
else:
i = 1
s = a + b
while 1:
s += i
if s % 2 == 0 and s // 2 >= b:
print(i)
break
i -= -1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for j in range(t):
z = input().split(" ")
a = abs(int(z[0]) - int(z[1]))
if a % 2 == 0:
i = int(a**0.5)
while not (a <= int((i**2 + i) / 2) and (i % 4 == 0 or i % 4 == 3)):
i -= -1
else:
i = int(a**0.5)
while not (a <= int((i**2 + i) / 2) and (i % 4 == 1 or i % 4 == 2)):
i -= -1
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def delta(x):
l, r = -1, 100000
while l + 1 < r:
mid = l + r >> 1
tot = mid * (mid + 1) // 2
if tot < x:
l = mid
else:
r = mid
if (r * (r + 1) // 2 - x) % 2 != 0:
return r + 1 + r % 2
else:
return r
t = int(input())
for i in range(t):
a, b = map(int, input().split())
print(delta(abs(a - b)))
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
c = "Just test!!!"
for _ in [0] * int(input()):
a, b = map(int, input().split())
d = abs(a - b)
i = int(((8 * d + 1) ** 0.5 - 1) / 2)
s = i * (i + 1) // 2
while (s ^ d) % 2 or s < d:
i += 1
s += i
print(i)
|
ASSIGN VAR STRING FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = input().strip().split(" ")
a, b = [int(a), int(b)]
c = abs(a - b)
flag = 0
i = 0
sum = 0
if c == 0:
print(0)
else:
while True:
i += 1
sum += i
if sum >= c and (sum - c) % 2 == 0:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER VAR NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
else:
i = 1
while 1:
r = i * (i + 1) // 2
if (abs(b - a) + r) % 2 == 0 and (abs(b - a) + r) // 2 <= r:
break
i += 1
print(i)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
if a == b:
print("0")
else:
if a > b:
b, a = a, b
Sum = a
for i in range(1, 100000000):
Sum = Sum + i
if Sum >= b and (Sum - b) % 2 == 0:
print(i)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for hasju in range(int(input())):
a, b = map(int, input().split())
raz = abs(a - b)
razch = raz % 2
c = 1
while raz > 0:
raz -= c
c += 1
c -= 1
while (c - 1) // 2 % 2 == razch:
c += 1
print(c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
cusum = [0] * 50000
cusum[0] = 1
for i in range(1, len(cusum)):
cusum[i] = cusum[i - 1] + i + 1
for i in range(n):
a, b = list(map(int, input().split()))
m = min(a, b)
a -= m
b -= m
number = max(a, b)
if number == 0:
print(0)
continue
stop = False
idx = -1
if number >= cusum[12500]:
idx = 12500
elif number >= cusum[25000]:
idx = 25000
elif number >= cusum[37500]:
idx = 37500
elif number >= cusum[44715]:
idx = 44715
while not stop:
idx += 1
if cusum[idx] >= number and (cusum[idx] - number) % 2 == 0:
stop = True
print(idx + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
ans = 1
a, b = map(int, input().split())
if a > b:
a, b = b, a
if a == b:
print(0)
continue
while a < b:
a += ans
ans += 1
while (a - b) % 2 != 0:
a += ans
ans += 1
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = [int(i) for i in input().split()]
a, b = min(a, b), max(a, b)
k = b - a
n = (-1 + (1 + 8 * k) ** 0.5) / 2
n = int(n)
k -= n * (n + 1) // 2
if k == 0:
print(n)
continue
n += 1
k -= n
if abs(k) % 2 == 0:
print(n)
elif abs(k - n - 1) % 2 == 0:
print(n + 1)
else:
print(n + 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from sys import stdin, stdout
v = [0]
for i in range(1, 100000):
v.append(v[-1] + i)
n = int(stdin.readline())
for i in range(n):
a, b = map(int, stdin.readline().split())
if a == b:
stdout.write("0\n")
else:
c = 0
for j in v:
c += 1
s = a + b + j
if s % 2 == 0 and s >= a * 2 and s >= b * 2:
stdout.write(str(c - 1) + "\n")
break
|
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for tcase in range(int(input())):
a, b = list(map(int, input().split()))
if a == b:
print(0)
else:
delta = abs(b - a)
i = 1
sm = 0
while sm < delta:
sm += i
i += 1
while sm % 2 != delta % 2:
sm += i
i += 1
print(i - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
d = abs(n - k)
q = 0
v = 0
while v < d:
q = q + 1
v = v + q
if v == d:
print(q)
elif v % 2 == d % 2:
print(q)
else:
while v % 2 != d % 2:
q = q + 1
v = v + q
print(q)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
nums = input().split(" ")
a = int(nums[0])
b = int(nums[1])
d = abs(a - b)
if d == 0:
print(0)
continue
i = 1
while True:
sum = (i + 1) * i / 2
if sum % 2 != d % 2:
i += 1
continue
if d > sum:
i += 1
continue
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def solve(n):
if int((8 * n + 1) ** (1 / 2)) == (8 * n + 1) ** (1 / 2):
x = (int((8 * n + 1) ** (1 / 2)) - 1) // 2
else:
x = (int((8 * n + 1) ** (1 / 2)) + 1) // 2
c = x * (x + 1) // 2
if (c - n) % 2 == 0:
return x
elif ((x + 1) * (x + 2) // 2 - n) % 2 == 0:
return x + 1
else:
return x + 2
t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
print(solve(abs(a - b)))
|
FUNC_DEF IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for i in range(n):
a, b = map(int, input().split())
d = abs(a - b)
s = 1
c = 1
if d == 0:
print(0)
else:
while s < d or s % 2 != d % 2:
c += 1
s = c * (c + 1)
s /= 2
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def fun(n):
p = int(pow(2 * n, 1 / 2))
if p * (p + 1) / 2 < n and (p + 1) * (p + 2) >= n:
return p + 1
else:
return p
n = int(input())
for i in range(0, n):
a, b = map(int, input().split())
t = max(a, b) - min(a, b)
m = fun(t)
if (m * (m + 1) // 2 - t) % 2 == 0:
print(m)
elif ((m + 1) * (m + 2) // 2 - t) % 2 == 0:
print(m + 1)
else:
print(m + 2)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
c = abs(a - b)
d = (-1 + (1 + 8 * c) ** 0.5) / 2
if d == int(d):
print(int(d))
else:
d = int(d)
d += 1
e = abs(c - d * (d + 1) // 2)
if e % 2 == 0:
print(d)
elif d % 2 == 0:
print(d + 1)
else:
print(d + 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
arr = [0] * 100001
for i in range(1, 100001):
arr[i] = arr[i - 1] + i
for _ in range(int(input())):
a, b = map(int, input().split())
d = abs(a - b)
if d == 0:
print(0)
else:
for i in range(1, 100001):
if arr[i] >= d and (arr[i] - d) % 2 == 0:
print(i)
break
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def cal(k):
rs = 0
for i in range(1000000000):
rs += i
if rs == k:
return i
if rs > k and rs - k & 1 == 0:
return i
for test in range(int(input())):
a, b = map(int, input().split())
print(cal(abs(a - b)))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR RETURN VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
a, b = (int(i) for i in input().split())
if a == b:
print(0)
continue
l = 1
h = 10**9
while l < h:
m = (l + h) // 2
if m * (m + 1) // 2 >= abs(a - b):
h = m
else:
l = m + 1
if abs(a - b) % 2 == 0:
i = h
for i in range(h, 10**9):
if i * (i + 1) // 2 & 1 == 0:
break
print(i)
else:
i = h
for i in range(h, 10**9):
if i * (i + 1) // 2 & 1 != 0:
break
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
s = input().split()
a = int(s[0])
b = int(s[1])
x = max(a, b) - min(a, b)
s = 0
i = 1
while x > 0:
x -= i
i += 1
s += 1
if x < 0:
q = a + b + (max(a, b) - min(a, b) - x)
while q % 2 != 0:
q += i
i += 1
s += 1
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def cc(n):
c = 0
d = 0
while d < n or (d - n) % 2 == 1:
c += 1
d = c * (c + 1) / 2
return c
t = int(input())
for i in range(t):
a, b = list(map(int, input().split(" ")))
a = abs(a - b)
print(cc(a))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from time import sleep
t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
if a == b:
print(0)
else:
if b > a:
a, b = b, a
x = 1
d = a - b
while True:
sa = (x * (x + 1) // 2 - d) / 2
sb = (x * (x + 1) // 2 + d) / 2
if sa >= 0 and int(sa) == sa and int(sb) == sb:
print(x)
break
x += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def find_min_n_bigger_than(diff):
l, r = 0, 10**5
while r - l > 1:
mid = (l + r) // 2
n_sum = int(mid * (mid + 1) / 2)
if n_sum < diff:
l = mid
else:
r = mid
return r
def solve(a, b):
a, b = max(a, b), min(a, b)
if a == b:
return 0
candidate = find_min_n_bigger_than(a - b)
qq = [(candidate + i) for i in range(4)]
for ss in qq:
if ss * (ss + 1) / 2 % 2 == (a - b) % 2:
return ss
n = int(input())
for i in range(n):
a, b = map(int, input().split())
print(solve(a, b))
|
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
e = int(input())
for i in range(e):
a, b = map(int, input().split())
ans = 0
s = 0
while (
s * (s + 1) // 2 < max(a, b) - min(a, b)
or s * (s + 1) // 2 % 2 != (max(a, b) - min(a, b)) % 2
):
s += 1
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def bin(x):
l = 0
r = 1000000000
lst = 0
while l + 1 < r:
m = (l + r) // 2
tc = m * 4
if (tc + 1) * (tc // 2) >= x:
r = m
lst = tc
else:
l = m
return lst
def bin1(x):
l = 1
r = 1000000000
lst = 0
while l + 1 < r:
m = (l + r) // 2
tc = m * 2
if (tc + 1) * (tc // 2) >= x:
r = m
lst = tc
else:
l = m
return lst
for i in range(int(input())):
x, y = map(int, input().split())
if x == y:
print(0)
continue
d = abs(x - y)
if d % 2 == 0:
k = bin(d)
kk = k - 1
if (kk + 1) * (kk // 2) + (kk + 1) // 2 >= d:
print(kk)
else:
print(k)
else:
k = bin1(d)
if k // 2 % 2 == 1:
kk = k - 1
if (kk + 1) * (kk // 2) + (kk + 1) // 2 >= d:
print(kk)
else:
print(k)
else:
kk = k - 2
if (kk + 1) * (kk // 2) >= d:
kkk = kk - 1
if (kkk + 1) * (kkk // 2) + (kkk + 1) // 2 >= d:
print(kkk)
else:
print(kk)
else:
print(k + 1)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def cal(n, diff):
delta = int(n * (n + 1) // 2)
if (delta - diff) % 2 == 0:
return True
else:
return False
def solve():
n, m = [int(x) for x in input().split()]
diff = abs(n - m)
delta = abs(n - m) * 2
left = 0
right = 1000000000
ans = float("inf")
while left <= right:
mid = int((left + right) // 2)
if mid * (mid + 1) >= delta:
if cal(mid, diff):
ans = min(ans, mid)
elif cal(mid + 1, diff):
ans = min(mid + 1, ans)
elif cal(mid + 2, diff):
ans = min(mid + 2, ans)
right = mid - 1
else:
left = mid + 1
print(ans)
t = int(input())
for test in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
def bin_search(d, lo, hi):
if lo + 1 == hi:
return hi
mid = (lo + hi) // 2
if mid * (mid + 1) // 2 >= d:
hi = mid
else:
lo = mid
return bin_search(d, lo, hi)
for _ in range(t):
a, b = list(map(int, input().split()))
d = abs(a - b)
if d == 0:
print(0)
continue
count = bin_search(d, 0, 10**6)
while count * (count + 1) // 2 % 2 != d % 2:
count += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from sys import stdin
for _ in range(int(input())):
a, b = map(int, input().split())
x = max(a, b) - min(a, b)
s = 0
ans = 0
for i in range(0, 100000):
s += i
if s - x >= 0 and (s - x) % 2 == 0:
ans = i
break
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
import sys
input = sys.stdin.readline
def solveeven(border):
l = -1
r = 10**5
while r - l > 1:
m = (r + l) // 2
num = m * 2 if m % 2 == 0 else m * 2 + 1
if num * (num + 1) // 2 >= border:
r = m
else:
l = m
return r * 2 if r % 2 == 0 else r * 2 + 1
def solveodd(border):
l = -1
r = 10**5
while r - l > 1:
m = (r + l) // 2
num = m * 2 if m % 2 == 1 else m * 2 + 1
if num * (num + 1) // 2 >= border:
r = m
else:
l = m
return r * 2 if r % 2 == 1 else r * 2 + 1
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for a, b in Query:
diff = abs(a - b)
if diff % 2 == 0:
print(solveeven(diff))
else:
print(solveodd(diff))
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from sys import stdin
n = int(stdin.readline().strip())
dif = 0
def can(x):
y = x * (x + 1)
y = y // 2
if y <= dif:
return True
return False
def fur(x):
y = x * (x + 1)
y = y // 2
return y
for c in range(n):
a, b = map(int, stdin.readline().strip().split())
dif = abs(a - b)
low = 0
high = 10**9
while high - low > 1:
mid = low + high
mid = mid // 2
if can(mid):
low = mid
else:
high = mid
for i in range(max(low - 7, 0), high + 7):
if fur(i) >= dif and dif % 2 == fur(i) % 2:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
n, m = map(int, input().split())
n, m = min(n, m), max(n, m)
l, r = -1, 100000
while r - l > 1:
m1 = (l + r) // 2
if m1 * (m1 + 1) // 2 >= m - n:
r = m1
else:
l = m1
while (r * (r + 1) // 2 % 2 + m - n) % 2 == 1:
r += 1
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def possible(diff, x):
if x * (x + 1) // 2 >= diff and diff % 2 == x * (x + 1) // 2 % 2:
return 1
return 0
for _ in range(int(input())):
a, b = map(int, input().split())
if 1:
diff = abs(b - a)
x = 0
while possible(diff, x) == 0:
x += 1
print(x)
|
FUNC_DEF IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for t in range(int(input())):
a, b = map(int, input().split())
if b < a:
a, b = b, a
for i in range(100000):
sa = i * (i + 1) // 2 + b - a
if sa % 2 == 0:
sa //= 2
sb = sa - b + a
if sb >= 0 and sa >= 0:
print(i)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
ls = []
prev = 0
for i in range(int(10**5) + 1):
prev += i
ls.append(prev)
t = int(input())
while t:
a, b = map(int, input().split())
c = min(a, b)
d = max(a, b)
ans = 10**9 + 1
for i in range(int(10**5) + 1):
if c + ls[i] >= d:
if (c + ls[i] - d) % 2 == 0:
ans = min(ans, i)
print(ans)
t -= 1
|
ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def summ(n):
return n * (n + 1) // 2
for _ in range(int(input())):
a, b = map(int, input().split())
if a > b:
a, b = b, a
if a == b:
print(0)
continue
n = 1
while 1:
XX = a + b + summ(n)
if XX % 2 == 0:
x = XX // 2
if x - a >= 0 and x - b >= 0 and 2 * x - a - b == summ(n):
print(n)
break
n += 1
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
import sys
reader = (map(int, s.split()) for s in sys.stdin)
(t,) = next(reader)
for _ in range(t):
a, b = next(reader)
if a == b:
print(0)
continue
d = abs(a - b)
n = int((2 * d) ** 0.5)
s = n * (n + 1) // 2
if s < d:
n += 1
s += n
while s % 2 != d % 2:
n += 1
s += n
print(n)
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def func(m):
return m * (m + 1) // 2
def check(m, d):
return func(m) >= d
for t in range(int(input())):
a, b = map(int, input().split())
d = abs(b - a)
low = 0
high = 1000000000
ans = None
while low <= high:
mid = (low + high) // 2
if check(mid, d):
ans = mid
high = mid - 1
else:
low = mid + 1
while func(ans) % 2 != d % 2:
ans += 1
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
exec(
int(input())
* """a,b=map(int,input().split());d=abs(a-b);i=0
while d%2or d>0:i+=1;d-=i
print(i);"""
)
|
EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = list(map(int, input().split()))
a, b = max(a, b), min(a, b)
d = a - b
ans = 0
if d != 0:
ans = int(((1 + 8 * d) ** (1 / 2) - 1) / 2) - 1
while (ans * (ans + 1) // 2 - d) % 2 != 0 or ans * (ans + 1) // 2 - d < 0:
ans += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER WHILE BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
c, d = [int(x) for x in input().split()]
a = max(c, d)
b = min(c, d)
d = a - b
n = (-1 + (1 + 8 * d) ** 0.5) / 2
if n > int(n):
n = int(n) + 1
else:
n = int(n)
newB = b + (1 + n) * n // 2
while (newB - a) % 2 == 1:
n += 1
newB += n
print(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
aa = max(a, b)
bb = min(a, b)
if aa == bb:
print(0)
else:
x = aa - bb
y = -1 + (1 + 8 * x) ** (1 / 2)
if y / 2 == y // 2:
print(int(y // 2))
else:
y = y // 2 + 1
su = y * (y + 1) // 2
while (su - x) % 2 != 0:
y += 1
su += y
print(int(y))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def mlt():
return map(int, input().split())
def f(x, df):
sm = x * (x + 1) // 2
if sm < df:
return 0
return sm % 2 == df % 2
def dolv():
x, y = mlt()
if x == y:
print(0)
return
res = 0
df = abs(x - y)
while not f(res, df):
res += 1
print(res)
for _ in range(int(input())):
dolv()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def solve(a, b):
diff = abs(a - b)
n = float("inf")
low = 0
high = 10**15
while low <= high:
mid = low + (high - low) // 2
if mid * (mid + 1) >= 2 * diff:
n = mid
high = mid - 1
else:
low = mid + 1
if (a + b) % 2 == 0:
while n * (n + 1) // 2 % 2 != 0:
n += 1
else:
while n * (n + 1) // 2 % 2 == 0:
n += 1
print(n)
def main():
t = int(input())
for i in range(t):
a, b = map(int, input().split())
solve(a, b)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for i in range(n):
a, b = map(int, input().split(" "))
dif = abs(a - b)
if dif == 0:
print(0)
else:
l, r = 1, 100000
while l < r:
m = (l + r) // 2
res = (m + 1) * m / 2
if res == dif:
print(m)
break
elif res < dif:
l = m + 1
else:
r = m
else:
while ((l + 1) * l / 2 - dif) % 2 == 1:
l += 1
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for i in range(n):
a, b = map(int, input().split(" "))
d = abs(a - b)
if d == 0:
print(0)
else:
for i in range(4 - d % 2 * 2, 10**5, 4):
if i * (i + 1) // 2 >= d:
if i * (i - 1) // 2 >= d:
print(i - 1)
else:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def times(a, b):
if a == b:
return 0
val = abs(b - a)
sum = 1
i = 1
while True:
while sum <= val:
if sum == val:
return i
else:
i += 1
sum += i
val += 2
t = int(input())
for i in range(t):
a, b = map(int, input().strip().split())
print(times(a, b))
|
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR VAR IF VAR VAR RETURN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def f():
a, b = [int(s) for s in input().split()]
if a < b:
a, b = b, a
need = a - b
if need == 0:
return 0
n = int((2 * need) ** 0.5)
if n * (n + 1) >= 2 * need:
x = n
else:
x = n + 1
while (x * (x + 1) // 2 - need) % 2:
x += 1
return x
t = int(input())
for i in range(t):
print(f())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
while t > 0:
e, d = [int(i) for i in input().split()]
k = 10000000000000000
a = max(e, d)
b = min(e, d)
diff = abs(a - b)
sum = diff
inte = 0
for i in range(1, k):
if diff == 0:
i -= 1
break
inte += i
if inte < sum:
pass
elif inte == sum:
break
elif (inte + sum) % 2 == 0:
break
print(i)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def s(n):
return n * (n + 1) // 2
def c(n, d):
m = s(n)
if m < d:
return False
return m % 2 == d % 2
for _ in range(int(input())):
a, b = map(int, input().split())
q = abs(a - b)
n = 0
while not c(n, q):
n += 1
print(n)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
import sys
n = int(sys.stdin.readline().rstrip())
ab = map(int, sys.stdin.read().split())
ab = list(zip(*([ab] * 2)))
def main():
for a, b in ab:
x = abs(b - a)
if x == 0:
yield 0
continue
l = 0
r = x + 1
while l + 1 < r:
m = (l + r) // 2
if (1 + m) * m // 2 >= x:
r = m
else:
l = m
if ((1 + r) * r // 2 - x) % 2 == 0:
yield r
elif r + 1 & 1:
yield r + 1
else:
yield r + 2
ans = main()
print(*ans, sep="\n")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST VAR NUMBER FUNC_DEF FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER EXPR BIN_OP VAR NUMBER EXPR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = map(int, input().split())
m = abs(a - b)
n = int((m * 2) ** (1 / 2))
while n * (n + 1) / 2 < m or (n * (n + 1) / 2 - m) % 2 == 1:
n += 1
print(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for tc in range(int(input())):
a, b = map(int, input().split())
d = abs(a - b)
tt = int((2 * d) ** 0.5)
if a == b:
print(0)
elif abs(a - b) == 1:
print(1)
elif 2 * d == tt**2 + tt:
print(tt)
elif abs(a - b) > 1:
i = tt
while i < d + d:
t = i * (i + 1) // 2
if t > d:
if (t + d) % 2 == 0:
print(i)
break
i += 1
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
inp = list(map(int, input().split()))
a = inp[0]
b = inp[1]
x = abs(a - b)
if x == 0:
print(0)
else:
t = 1
while (x + t * (t + 1) // 2) % 2 != 0 or t * (t + 1) // 2 < x:
t += 1
print(t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
q = int(input())
while q:
a, b = map(int, input().split())
sum_ = a + b
i = 0
while (i * (i + 1) // 2 + sum_) % 2 != 0 or i * (i + 1) // 2 + sum_ < 2 * max(a, b):
i += 1
print(i)
q -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = map(int, input().split())
d = abs(a - b)
if d == 0:
print(0)
continue
delta = (1 / 4 + 2 * d) ** 0.5
t = -1 / 2 + delta
if int(t) == t:
t = int(t)
else:
t = int(t + 1)
while (t - 1) // 2 % 2 ^ d % 2 == 0:
t += 1
print(t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = sorted(map(int, input().split()))
if a == b:
print(0)
continue
ans, s = 0, 0
while True:
ans += 1
s += ans
if s < b - a:
continue
if (s - b + a) % 2:
continue
x = (s - b + a) // 2
if x <= s:
print(ans)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def check(num):
temp = num * (num + 1) // 2
if temp <= b - a:
return 1
else:
return 0
def bin_search(l, r):
while l < r:
mid = (l + r + 1) // 2
if check(mid):
l = mid
else:
r = mid - 1
return l
MAX = int(1000000000.0) + 1
t = int(input())
for _ in range(t):
ans = 0
a, b = [int(i) for i in input().split()]
if a == b:
print(0)
else:
m = max(a, b)
mi = min(a, b)
a = mi
b = m
x = bin_search(1, MAX)
t1 = x * (x + 1) // 2
t2 = a + t1
diff = b - t2
if diff == 0:
print(x)
else:
t3 = (x + 1) * (x + 2) // 2
d1 = a + t3 - b
y = x + 1
if d1 % 2 == 0:
print(x + 1)
else:
ans = y
y += 1
ans += 1
d1 += y
if d1 % 2 != 0:
ans += 1
print(min(ans, x + 2 * diff))
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from sys import stdin
t = int(stdin.readline())
while t:
a, b = map(int, stdin.readline().split())
c = 0
d = abs(a - b)
while d > 0 or d & 1:
c += 1
d -= c
print(c)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def rint():
return int(input())
def rints():
return list(map(int, input().split()))
t = rint()
for _ in range(t):
a, b = sorted(rints())
mn = b - a if a % 2 == b % 2 else b - a + 2
for i in range(10**6):
s = i * (i + 1) // 2
if s >= b - a and (s - (b - a)) % 2 == 0:
print(i)
break
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = input().split()
a = int(a)
b = int(b)
dif = abs(a - b)
n = int((2 * dif) ** 0.5)
for j in range(5):
S = int(n * (n + 1) / 2)
if S >= dif and (S - dif) % 2 == 0:
print(n)
break
n += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
aa, bb = min(a, b), max(a, b)
c = bb - aa
i = 0
ans = 0
if c == 0:
print(0)
else:
while 1:
i += 1
ans += i
if ans >= c and (ans - c) % 2 == 0:
print(i)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER VAR NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for i in range(n):
a, b = map(int, input().split())
d = max(a, b) - min(a, b)
n = 0
while True:
s = n * (n + 1) // 2
if s >= d and (s - d) % 2 == 0:
break
n += 1
print(n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for i in range(int(input())):
inp1, inp2 = map(int, input().split())
a1 = max(inp1, inp2)
a2 = min(inp1, inp2)
if a1 == a2:
print(0)
continue
else:
i = int(((1 + 8 * (a1 - a2)) ** 0.5 - 1) // 2)
j = 1
while j:
if i * (i + 1) // 2 >= a1 - a2:
if (a1 + a2 + i * (i + 1) // 2) % 2 == 0:
print(i)
j = 0
continue
i = i + 1
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for i in range(t):
a, b = map(int, input().split())
if a == b:
print("0")
continue
j = 1
s = a + b
if abs(a - b) > 1000:
k = int(abs((a - b) ** 0.5) * 1.4)
s = a + b + (k + 1) * (k / 2)
j = k + 1
while j > 0:
s = s + j
if s >= max(a, b) * 2 and s % 2 == 0:
print(j)
break
else:
j += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
dif = abs(a - b)
if dif == 0:
print(0)
continue
i = 1
while True:
n = i * (i + 1) // 2
if n % 2 != dif % 2:
i += 1
continue
elif dif > n:
i += 1
continue
else:
print(i)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
t = intput()
for _ in range(t):
a, b = intsput()
diff = abs(a - b)
s = 0
for i in range(100000000000):
s += i
if s >= diff and (diff - s) % 2 == 0:
break
print(i)
|
FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
mx = max(a, b)
i = 0
n = 1
while 1:
if (a + +b + i) // 2 >= mx and (a + b + i) % 2 == 0:
print(n - 1)
break
else:
i += n
n += 1
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
import sys
input = lambda: sys.stdin.readline().strip("\r\n")
for _ in range(int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
else:
if a < b:
a, b = b, a
for i in range(1, a + 1):
x = i * (i + 1) // 2
if a - b <= x and (a - b) % 2 == x % 2:
print(i)
break
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
ans = 0
a, b = map(int, input().split())
if a > b:
a, b = b, a
if a != b:
for i in range(100000):
s = i * (i + 1) // 2
if s > 100000000000:
break
cv = a + b + s
if cv % 2:
continue
if cv >= 2 * b:
print(i)
break
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
l = []
for i in range(1, 100005):
l.append(i * (i + 1) // 2)
for a0 in range(int(input())):
a, b = map(int, input().split())
if a > b:
a, b = b, a
if a == b:
print(0)
continue
for i in range(0, 100004):
if l[i] >= b - a and (l[i] + a + b) % 2 == 0:
print(i + 1)
break
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
q = int(input())
cache = {}
while q:
a, b = input().split()
a = int(a)
b = int(b)
diff = abs(a - b)
if cache.get(diff, None) is not None:
print(cache.get(diff))
else:
start = 0
value = 0
while True:
if start + value < diff:
value = start + value
start += 1
continue
if (start + value) % 2 == diff % 2:
print(start)
cache.update({diff: start})
break
value = start + value
start += 1
q -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT WHILE VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NONE NONE EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR DICT VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for _ in range(n):
line = input().split()
a, b = tuple(map(lambda x: int(x), line))
if a > b:
diff = a - b
elif a < b:
diff = b - a
else:
print("0")
continue
t = 1
while t * (t + 1) < 2 * diff:
t *= 2
head, tail = t // 2, t
while tail - head >= 2:
mid = (head + tail) // 2
if mid * (mid + 1) < 2 * diff:
head = mid
else:
tail = mid
mod_diff, mod_tail = diff % 2, (tail - 1) % 4 + 1
if mod_diff == 1 and mod_tail >= 3:
tail = tail + 5 - mod_tail
elif mod_diff == 0 and mod_tail < 3:
tail = tail + 3 - mod_tail
print(tail)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
gpf = [0]
for i in range(1, 200000):
gpf.append(i * (i + 1) // 2)
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
d = abs(a - b)
ind = 0
for i in range(len(gpf)):
if gpf[i] >= d:
ind = i
break
if gpf[ind] == d:
print(ind)
elif not (gpf[ind] - d) % 2:
print(ind)
else:
while (gpf[ind] - d) % 2:
ind += 1
print(ind)
|
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
for _ in [0] * int(input()):
a, b = sorted([int(x) for x in input().split()])
diff = abs(a - b)
ans = 0
sums = 0
while sums < diff or sums % 2 != diff % 2:
ans += 1
sums += ans
print(ans)
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
n = int(input())
for i in range(n):
a, b = list(map(int, input().split(" ")))
d = abs(a - b)
s = 0
if d == 0:
print(0)
continue
for i in range(1, int(1000000000.0)):
s += i
if d <= s and (i - 1) // 2 % 2 != d % 2:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
def answer(a, b):
n = 10**6
for i in range(n):
k = i * (i + 1) / 4 - abs(a - b) / 2
if k == int(k) and k >= 0:
return i
t = int(input())
for i in range(t):
a, b = map(int, input().split())
print(answer(a, b))
|
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer β the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
for i in range(4 * 10**5):
if (i * (i + 1) // 2 + a + b) % 2 == 0:
if i * (i + 1) // 2 >= abs(a - b):
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.