description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for i in range(int(input())):
x = int(input())
d = x // 2
if x == 2:
print(0)
elif x % 2 == 0:
if x / 2 % 2 == 0:
print((d + 1) * (d - 1) - 1)
else:
print((d + 2) * (d - 2) - 1)
else:
print(d * (d + 1) - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for _ in range(int(input())):
n = int(input())
if n % 2 != 0:
print(n // 2 * (n // 2 + 1) - 1)
elif n % 4 == 0:
k = n // 2 - 1
k2 = n - k
print(k * k2 - 1)
elif n == 2:
print(0)
else:
kk = n // 2 - 2
kk2 = n - kk
print(kk2 * kk - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for _ in range(t):
n = int(input())
if n % 2:
val = n // 2
print(val * (val + 1) - 1)
elif n == 2:
print(0)
else:
mid, k = n // 2, 0
if mid % 2 == 0:
k = 1
else:
k = 2
print((mid - k) * (mid + k) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for _ in range(int(input())):
n = int(input())
if n == 2:
print("0")
elif n % 2 != 0:
k = n // 2
p = k + 1
print(k * p - 1)
else:
k = n // 2 - 1
p = k + 2
if k % 2 != 0 and p % 2 != 0:
print(k * p - 1)
else:
k = k - 1
p = p + 1
print(k * p - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def gcd(a, b):
while b:
a, b = b, a % b
return a
for _ in range(int(input())):
n = int(input())
if n % 2 == 1:
a, b = (n + 1) // 2, (n + 1) // 2 - 1
elif n == 2:
a, b = 1, 1
elif n // 2 % 2 == 0:
a, b = n // 2 + 1, n // 2 - 1
else:
a, b = n // 2 + 2, n // 2 - 2
g = gcd(a, b)
l = int(a * b / g)
print(a * b - 1)
|
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
k = []
for x in range(t):
N = int(input())
k = [N - 2]
if N % 2 == 0:
if N == 2:
print(k[0])
elif int(N / 2) % 2 == 0:
print((int(N / 2) - 1) * (int(N / 2) + 1) - 1)
else:
print((int(N / 2) - 2) * (int(N / 2) + 2) - 1)
else:
print(int(N / 2) * (int(N / 2) + 1) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def greatestCommonDivisor(x, y):
if y == 0:
return x
return greatestCommonDivisor(y, x % y)
def solutionFunc(x, y):
gross = greatestCommonDivisor(x, y)
part = x * y
return part // gross - gross
result = ""
for _ in range(int(input())):
number = int(input())
if number % 2 == 1:
result += str(solutionFunc((number - 1) // 2, (number + 1) // 2)) + "\n"
elif number == 2:
result += "0\n"
elif (number // 2 - 1) % 2 == 1:
result += str(solutionFunc(number // 2 - 1, number // 2 + 1)) + "\n"
else:
result += str(solutionFunc(number // 2 - 2, number // 2 + 2)) + "\n"
print(result)
|
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER STRING IF VAR NUMBER VAR STRING IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for T in range(t):
N = int(input())
if N % 2 == 1:
a = (N - 1) // 2
b = (N + 1) // 2
elif N == 2:
a = 1
b = 1
elif N % 4 == 0:
a = N // 2 - 1
b = N // 2 + 1
else:
a = N // 2 - 2
b = N // 2 + 2
print(a * b - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for t in range(int(input())):
N = int(input())
if N % 2 != 0:
print((N**2 - 1) // 4 - 1)
elif N == 2:
print(0)
elif (N // 2 - 1) % 2 != 0:
print((N // 2 - 1) * (N // 2 + 1) - 1)
else:
print((N // 2 - 2) * (N // 2 + 2) - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def g(a, b):
if b == 0:
return a
if a < b:
return g(b, a)
return g(b, a % b)
t = int(input())
for _ in range(t):
n = int(input())
ans = 0
if n % 2 == 0:
m = n // 2
if m % 2 != 0:
a = n // 2 - 2
b = n // 2 + 2
gc = g(a, b)
lc = a * b // gc
ans = lc - gc + 1
else:
a = n // 2 - 1
b = n // 2 + 1
gc = g(a, b)
lc = a * b // gc
ans = lc - gc + 1
else:
ans = n // 2
ans *= n // 2 + 1
if n == 2:
ans = 1
print(ans - 1)
|
FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for i in range(t):
n = int(input())
if n == 2:
print(0)
continue
if n % 2 == 1:
print(int((n - 1) // 2 * (n + 1) // 2 - 1))
elif (n / 2 - 1) % 2 == 1:
print(int((n // 2 - 1) * (n // 2 + 1) - 1))
else:
print(int((n // 2 - 2) * (n // 2 + 2) - 1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def gcd(a, b):
while b:
a, b = b, a % b
return abs(a)
t = int(input())
for x in range(t):
N = int(input())
k = 0
for i in reversed(range(1, N // 2 + 1)):
if gcd(i, N - i) == 1:
k = i
break
print(k * (N - k) - 1)
|
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def gcd(a, b):
while a != b:
if a > b:
a = a - b
else:
b = b - a
return a
for i in range(int(input())):
n = int(input())
ans = 0
x = 0
if n == 2:
ans = 0
elif n == 4:
ans = 2
elif n % 2 == 0:
x, y = n // 2 - 1, n // 2 + 1
c, d = n // 2 - 2, n // 2 + 2
if x % 2 != 0 and y % 2 != 0:
ans = x * y - 1
elif c % 2 != 0 and d % 2 != 0:
ans = c * d - 1
elif x % 2 != 0 or y % 2 != 0:
a1 = gcd(x, y)
if a1 == 1:
ans = y * x - 1
elif c % 2 != 0 or d % 2 != 0:
a2 = gcd(c, d)
if a2 == 1:
ans = c * d - 1
else:
ans = (n // 2 + 1) * (n // 2) - 1
print(ans)
|
FUNC_DEF WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for _ in range(t):
n = int(input())
if n == 2:
print(0)
elif n % 2 == 1:
print(n // 2 * (n // 2 + 1) - 1)
else:
a = n // 2 - 1
b = n // 2 + 1
if a % 2 == 1:
print(a * b - 1)
else:
print((a - 1) * (b + 1) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for i in range(int(input())):
n = int(input())
if n == 2:
print(0)
elif n % 2 != 0:
print((n - 1) // 2 * ((n + 1) // 2) - 1)
elif n % 2 == 0 and n // 2 % 2 == 0:
print((n // 2 - 1) * (n // 2 + 1) - 1)
elif n % 2 == 0 and n // 2 % 2 != 0:
print((n // 2 - 2) * (n // 2 + 2) - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER
|
She does her utmost to flawlessly carry out a person's last rites and preserve the world's balance of yin and yang.
Hu Tao, being the little prankster she is, has tried to scare you with this graph problem! You are given a connected undirected graph of n nodes with m edges. You also have q queries. Each query consists of two nodes a and b.
Initially, all edges in the graph have a weight of 0. For each query, you must choose a simple path starting from a and ending at b. Then you add 1 to every edge along this path. Determine if it's possible, after processing all q queries, for all edges in this graph to have an even weight. If so, output the choice of paths for each query.
If it is not possible, determine the smallest number of extra queries you could add to make it possible. It can be shown that this number will not exceed 10^{18} under the given constraints.
A simple path is defined as any path that does not visit a node more than once.
An edge is said to have an even weight if its value is divisible by 2.
Input
The first line contains two integers n and m (2 β€ n β€ 3 β
10^5, n-1 β€ m β€ min{\left((n(n-1))/(2), 3 β
10^5\right)}).
Each of the next m lines contains two integers x and y (1 β€ x, y β€ n, xβ y) indicating an undirected edge between node x and y. The input will not contain self-loops or duplicate edges, and the provided graph will be connected.
The next line contains a single integer q (1 β€ q β€ 3 β
10^5).
Each of the next q lines contains two integers a and b (1 β€ a, b β€ n, a β b), the description of each query.
It is guaranteed that nq β€ 3 β
10^5.
Output
If it is possible to force all edge weights to be even, print "YES" on the first line, followed by 2q lines indicating the choice of path for each query in the same order the queries are given. For each query, the first line should contain a single integer x: the number of nodes in the chosen path. The next line should then contain x spaced separated integers p_i indicating the path you take (p_1 = a, p_x = b and all numbers should fall between 1 and n). This path cannot contain duplicate nodes and must be a valid simple path in the graph.
If it is impossible to force all edge weights to be even, print "NO" on the first line and the minimum number of added queries on the second line.
Examples
Input
6 7
2 1
2 3
3 5
1 4
6 1
5 6
4 5
3
1 4
5 1
4 5
Output
YES
2
1 4
4
5 3 2 1
5
4 1 2 3 5
Input
5 7
4 3
4 5
2 1
1 4
1 3
3 5
3 2
4
4 2
3 5
5 1
4 5
Output
NO
2
Note
Here is what the queries look like for the first test case (red corresponds to the 1st query, blue 2nd query, and green 3rd query):
<image> Notice that every edge in the graph is part of either 0 or 2 colored query edges.
The graph in the second test case looks like this:
<image> There does not exist an assignment of paths that will force all edges to have even weights with the given queries. One must add at least 2 new queries to obtain a set of queries that can satisfy the condition.
|
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def SameQuery(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
uf = UnionFind(n)
e = [[] for _ in range(n + 1)]
edges = []
for i in range(m):
u, v = map(int, input().split())
if uf.SameQuery(u, v):
edges.append((0, 0))
continue
uf.Unite(u, v)
e[u].append((v, i))
e[v].append((u, i))
edges.append((u, v))
q = int(input())
qs = [tuple(map(int, input().split())) for _ in range(q)]
table = [0] * m
res = []
for u, v in qs:
s = [u]
vis = [0] * (n + 1)
rev = [0] * (n + 1)
vis[u] = 1
while len(s):
x = s.pop()
for y, _ in e[x]:
if vis[y]:
continue
vis[y] = 1
s.append(y)
rev[y] = x
x = v
res.append([])
while x != u:
res[-1].append(x)
for y, i in e[x]:
if y == rev[x]:
table[i] ^= 1
x = y
break
res[-1].append(u)
res[-1].reverse()
if sum(table) == 0:
print("YES")
for r in res:
print(len(r))
print(*r)
else:
print("NO")
c = [0] * (n + 1)
for i in range(m):
if table[i] == 0:
continue
u, v = edges[i]
c[u] ^= 1
c[v] ^= 1
print(sum(c) // 2)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
She does her utmost to flawlessly carry out a person's last rites and preserve the world's balance of yin and yang.
Hu Tao, being the little prankster she is, has tried to scare you with this graph problem! You are given a connected undirected graph of n nodes with m edges. You also have q queries. Each query consists of two nodes a and b.
Initially, all edges in the graph have a weight of 0. For each query, you must choose a simple path starting from a and ending at b. Then you add 1 to every edge along this path. Determine if it's possible, after processing all q queries, for all edges in this graph to have an even weight. If so, output the choice of paths for each query.
If it is not possible, determine the smallest number of extra queries you could add to make it possible. It can be shown that this number will not exceed 10^{18} under the given constraints.
A simple path is defined as any path that does not visit a node more than once.
An edge is said to have an even weight if its value is divisible by 2.
Input
The first line contains two integers n and m (2 β€ n β€ 3 β
10^5, n-1 β€ m β€ min{\left((n(n-1))/(2), 3 β
10^5\right)}).
Each of the next m lines contains two integers x and y (1 β€ x, y β€ n, xβ y) indicating an undirected edge between node x and y. The input will not contain self-loops or duplicate edges, and the provided graph will be connected.
The next line contains a single integer q (1 β€ q β€ 3 β
10^5).
Each of the next q lines contains two integers a and b (1 β€ a, b β€ n, a β b), the description of each query.
It is guaranteed that nq β€ 3 β
10^5.
Output
If it is possible to force all edge weights to be even, print "YES" on the first line, followed by 2q lines indicating the choice of path for each query in the same order the queries are given. For each query, the first line should contain a single integer x: the number of nodes in the chosen path. The next line should then contain x spaced separated integers p_i indicating the path you take (p_1 = a, p_x = b and all numbers should fall between 1 and n). This path cannot contain duplicate nodes and must be a valid simple path in the graph.
If it is impossible to force all edge weights to be even, print "NO" on the first line and the minimum number of added queries on the second line.
Examples
Input
6 7
2 1
2 3
3 5
1 4
6 1
5 6
4 5
3
1 4
5 1
4 5
Output
YES
2
1 4
4
5 3 2 1
5
4 1 2 3 5
Input
5 7
4 3
4 5
2 1
1 4
1 3
3 5
3 2
4
4 2
3 5
5 1
4 5
Output
NO
2
Note
Here is what the queries look like for the first test case (red corresponds to the 1st query, blue 2nd query, and green 3rd query):
<image> Notice that every edge in the graph is part of either 0 or 2 colored query edges.
The graph in the second test case looks like this:
<image> There does not exist an assignment of paths that will force all edges to have even weights with the given queries. One must add at least 2 new queries to obtain a set of queries that can satisfy the condition.
|
import sys
input = sys.stdin.readline
m1 = lambda s: int(s) - 1
N, M = map(int, input().split())
e = [-1] * N
def find(i: int) -> int:
if e[i] < 0:
return i
e[i] = find(e[i])
return e[i]
def join(a: int, b: int) -> bool:
a, b = find(a), find(b)
if a == b:
return False
if e[a] > e[b]:
a, b = b, a
e[a] += e[b]
e[b] = a
return True
adj = [[] for _ in range(N)]
for _ in range(M):
a, b = map(m1, input().split())
if join(a, b):
adj[a].append(b)
adj[b].append(a)
P = [-1] * N
O = [0]
for i in O:
for j in adj[i]:
adj[j].remove(i)
P[j] = i
O.append(j)
Q = int(input())
C = [0] * N
Qs = []
for _ in range(Q):
a, b = map(m1, input().split())
C[a] += 1
C[b] += 1
Qs.append((a, b))
odd = sum(c & 1 for c in C)
assert odd % 2 == 0
if odd:
print("NO")
print(odd // 2)
exit()
print("YES")
B = []
for a, b in Qs:
V = [False] * N
x = a
while x != -1:
V[x] = True
x = P[x]
x = b
while not V[x]:
x = P[x]
anc = x
P1 = [a]
while P1[-1] != anc:
P1.append(P[P1[-1]])
P2 = [b]
while P2[-1] != anc:
P2.append(P[P2[-1]])
P1.pop()
P1 += P2[::-1]
B.append(str(len(P1)))
B.append(" ".join(str(x + 1) for x in P1))
print("\n".join(B))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF VAR IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 = sorted(list(map(int, input().split())))
r = a[1] - a[0]
r = int(r**0.5)
k = r * (r + 1) // 2
while not (a[0] - a[1] + k >= 0 and (a[0] - a[1] + k) % 2 == 0):
r += 1
k = r * (r + 1) // 2
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN 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$).
|
def par(i):
return i % 4 in (1, 2)
def calc(d):
l, r = 0, 10**9
while r - l > 1:
mid = (l + r) // 2
if (1 + mid) * mid // 2 > d:
r = mid
else:
l = mid
for i in range(max(0, l - 8), l + 8):
if (1 + i) * i // 2 >= d and par(i) == d % 2:
return i
return None
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
print(calc(abs(a - b)))
|
FUNC_DEF RETURN BIN_OP VAR NUMBER NUMBER NUMBER 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 IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NONE 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$).
|
for _ in range(int(input())):
ab = [int(x) for x in input().split()]
a = ab[0]
b = ab[1]
diff = abs(a - b)
mi = min(a, b)
ma = max(a, b)
arr = [0]
ans = -1
for i in range(diff + 2):
ne = arr[-1] + i
arr.append(ne)
if ne + mi == ma:
ans = i
break
if ne - diff > 0 and (ne - diff) % 2 == 0:
ans = i
break
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN 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$).
|
for i in range(int(input())):
a, b = map(int, input().split())
d = abs(a - b)
su = a + b
sq = int(pow(d, 0.5))
if a == b:
print(0)
else:
while 1:
st = sq * (sq + 1) // 2
if st >= d:
if (su + st) % 2 == 0:
break
sq = sq + 1
print(sq)
|
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP 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$).
|
i = input
for _ in range(int(i())):
a, b = map(int, i().split())
d = abs(a - b)
for r in range(99999):
if r * (r + 1) >= 2 * d and (r + 1) % 4 // 2 == d % 2:
print(r)
break
|
ASSIGN 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 FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER 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$).
|
tests = int(input())
for te in range(tests):
a, b = list(map(int, input().split()))
diff = abs(a - b)
for i in range(10**5):
c = i * (i + 1) // 2
if c >= diff and c % 2 == diff % 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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP 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$).
|
n = int(input())
for i in range(n):
x, y = map(int, input().split())
a = min(x, y)
b = max(x, y)
k = int((-1 + (1 + 4 * ((b - a) * 2)) ** 0.5) / 2)
if (b - a) % 2 == 0:
while True:
if (k**2 + k) % 4 == 0 and (k**2 + k) // 2 - (b - a) >= 0:
print(k)
break
k += 1
else:
while True:
if (k**2 + k) % 4 == 2 and (k**2 + k) // 2 - (b - a) >= 0:
print(k)
break
k += 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 FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP 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$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
i = 0
while True:
x = i * (i + 1) // 2
r = a + b + x
if r % 2 == 0 and r / 2 >= a and r / 2 >= b:
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 NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR 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$).
|
def add(res, d):
sum = res * (res + 1) // 2
if sum < d:
return 0
if sum % 2 == d % 2:
return 1
else:
return 0
for _ in range(int(input())):
a, b = (int(x) for x in input().split())
d = abs(a - b)
if d == 0:
print(0)
continue
res = 1
while not add(res, d):
res = res + 1
print(res)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR 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 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$).
|
def solve(a, b):
a = abs(a - b)
s = 0
i = 0
for i in range(a):
s += i
if s >= a:
break
if s == a:
return i
elif (s - a) % 2 == 0:
return i
elif i % 2 == 0:
return i + 1
else:
return i + 2
for i in range(int(input())):
a, b = map(int, input().split())
print(solve(a, b))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR VAR RETURN VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN 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 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 = [int(i) for i in input().split()]
i = 0
while i * (i + 1) // 2 < abs(a - b) or (i * (i + 1) // 2 - abs(a - b)) % 2 == 1:
i += 1
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 ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR 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$).
|
l = []
i = 1
count = 0
while 1:
count += i
l.append(count)
i += 1
if count > 1000000005:
break
def find(n):
low = 0
high = 44720
index = -1
while 1:
mid = (low + high) // 2
if low > high:
index = high
break
if l[mid] == n:
index = mid
break
elif l[mid] < n:
low = mid + 1
else:
high = mid - 1
return index
for _ in range(int(input())):
n, m = map(int, input().split())
dif = abs(n - m)
if dif == 0:
print(0)
else:
temp = find(dif)
while 1:
temp2 = temp * (temp + 1) // 2
if temp2 < dif:
temp += 1
elif (temp2 + n + m) % 2 == 0:
print(temp)
break
else:
temp += 1
|
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR 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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR 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$).
|
summation = []
p = 0
for i in range(100001):
p += i
summation.append(p)
for i in range(int(input())):
c, d = map(int, input().split())
a = min(c, d)
b = max(c, d)
diff = b - a
ans = 1000000001
for i in range(100001):
if a + summation[i] >= b:
if (a + summation[i] - b) % 2 == 0:
ans = min(ans, i)
print(ans)
|
ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR 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
|
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 test in range(t):
a, b = [int(i) for i in input().split()]
a, b = max(a, b) - min(a, b), 0
sum = 0
for i in range(10**9):
sum += i
if a % 2 == sum % 2:
if sum >= a:
print(i)
break
|
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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER BIN_OP 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$).
|
t = int(input())
for u in range(t):
i = input().split()
d = abs(int(i[0]) - int(i[1]))
for j in range(100000):
if d + d <= j * (j + 1) and j * (j + 1) // 2 % 2 == d % 2:
print(j)
break
|
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 BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR 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 ab(a, b):
if a == b:
return 0
if a > b:
a, b = b, a
for i in range(100000):
a = a + i
if a == b:
return i
elif a > b:
if (a - b) % 2 == 0:
return i
elif (a - b) % 2 != 0:
if (i + 1) % 2 != 0:
i = i + 1
return i
elif (i + 1) % 2 == 0:
i = i + 2
return i
times = int(input())
for i in range(times):
nums = input().split(" ")
print(ab(int(nums[0]), int(nums[1])))
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL 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):
c = list(map(int, input().split()))
x = abs(c[0] - c[1])
k = 0
p = (k + 1) * k // 2
while p < x or (p - x) % 2 != 0:
k += 1
p = (k + 1) * k // 2
print(k)
|
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 FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP 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$).
|
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if a == b:
print(0)
else:
i = 1
count = 0
su = a + b
while 1:
s = i * (i + 1) // 2
s1 = su + s
count += 1
if s1 % 2 == 0:
d1 = s1 // 2
d2 = s1 // 2
if a <= d1 and b <= d2:
print(count)
break
i += 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR 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$).
|
q = int(input())
for rere in range(q):
a, b = map(int, input().split())
d = abs(b - a)
i = 0
while i * (i + 1) // 2 < d:
i += 1
if d % 2 == i * (i + 1) // 2 % 2:
print(i)
else:
a = i * (i + 1) // 2 % 2
while i * (i + 1) // 2 % 2 == a:
i += 1
print(i)
|
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 WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR 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$).
|
t = int(input())
for testcase in range(t):
integers = [int(x) for x in input().split()]
a, b = integers[0], integers[1]
c = abs(b - a)
sq = (8 * c + 1) ** (1 / 2)
n = int((sq - 1) // 2)
ans = 0
triangular = n * (n + 1) // 2
while triangular < c or (triangular - c) % 2 != 0:
n += 1
triangular = n * (n + 1) // 2
print(int(n))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 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 calc(d):
return int((1 + 4 * d) ** 0.5 // 2)
t = int(input())
for nt in range(t):
a, b = map(int, input().split())
a, b = max(a, b), min(a, b)
d = a - b
if d % 2 == 0:
i = calc(2 * d)
while True:
if (i**2 + i) % 4 == 0 and i**2 + i - 2 * d >= 0:
print(i)
break
i += 1
else:
i = calc(2 * d)
while True:
if (i**2 + i) % 4 == 2 and i**2 + i - 2 * d >= 0:
print(i)
break
i += 1
|
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER 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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR WHILE NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER 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$).
|
n = int(input())
m = []
for i in range(n):
a, b = input().split()
m.append([a, b])
for i in m:
k = abs(int(i[0]) - int(i[1]))
t = int(pow(1 + 8 * k, 0.5)) // 2 - 1
p = 0
while p <= 3 * k:
p = t * (t + 1) // 2
if p == k:
break
if p - k > 0 and (p - k) % 2 == 0:
break
t += 1
r = pow(1 + 8 * p, 0.5)
result = (r - 1) // 2
print(int(result))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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$).
|
v = [0]
for i in range(1, 10**5):
v.append(v[-1] + i)
c = int(input())
for casos in range(c):
a, b = map(int, input().split())
sw = 0
if a == b:
print(0)
elif a < b:
while sw == 0:
l = a + b
for i in range(len(v)):
p = l + v[i]
if p % 2 == 0:
p = p // 2
if p >= a and p >= b:
print(i)
sw = 1
break
else:
while sw == 0:
l = a + b
for i in range(len(v)):
p = l + v[i]
if p % 2 == 0:
p = p // 2
if p >= a and p >= b:
print(i)
sw = 1
break
|
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP 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 ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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 case in range(int(input())):
cnt = 0
x = input().split()
m = abs(int(x[0]) - int(x[1]))
while m > 0:
cnt += 1
m -= cnt
m = -m
while m & 1:
cnt += 1
m += cnt
print(cnt)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR WHILE 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$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
if a > b:
a, b = b, a
k = 1
while a + k <= b:
a += k
k += 1
if a == b:
print(k - 1)
continue
for i in range(3):
a += k
k += 1
d = a - b
if d % 2 == 0:
print(k - 1)
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 ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP 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$).
|
for u in range(int(input())):
x, y = map(int, input().split())
ka = abs(x - y)
c = 0
for i in range(1000001):
if ka <= i * (i + 1) // 2 and (i + 1) // 2 % 2 == ka % 2:
c = i
break
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR 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$).
|
for i in range(int(input())):
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
l = -1
r = b - a
while r - l > 1:
m = (l + r) // 2
if a + (1 + m) * m // 2 >= b:
r = m
else:
l = m
if (a + (1 + r) * r // 2 - b) % 2 == 0:
print(r)
elif r % 2 == 1:
print(r + 2)
else:
print(r + 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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER 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$).
|
def bs(v):
l, r = -1, 10**5
while r - l > 1:
m = (r + l) // 2
if m * (m + 1) // 2 < v:
l = m
else:
r = m
return r
def solve(x, y):
if x > y:
x, y = y, x
d = y - x
k = bs(d)
u = k * (k + 1) // 2 - d
while u % 2 != 0 or u // 2 > k * (k + 1) // 2:
k += 1
u = k * (k + 1) // 2 - d
return k
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
res = solve(a, b)
print(res)
|
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 IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR 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 ASSIGN VAR 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$).
|
def main():
t = int(input())
for line in range(t):
a, b = (int(x) for x in input().split())
print(solver(a, b))
def solver(a, b):
diff = abs(a - b)
total = 0
x = 0
while not (total >= diff and (total - diff) % 2 == 0):
x += 1
total += x
return x
main()
|
FUNC_DEF 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR RETURN 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())
while T > 0:
a, b = map(int, input().split())
if a > b:
diff = a - b
else:
diff = b - a
op = 0
sums = 0
while True:
sums = sums + op
if sums >= diff and (sums - diff) % 2 == 0:
print(op)
break
op = op + 1
T = T - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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$).
|
from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if a == b:
print(0)
continue
x = max(a, b)
y = min(a, b)
ans = 0
while 1:
ans += 1
if ans * (ans + 1) // 2 >= x - y and ans * (ans + 1) // 2 % 2 == (x - y) % 2:
break
print(ans)
|
ASSIGN VAR 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP 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 ok(x):
res = x * (x + 1) // 2
return res >= delta and res & 1 == delta & 1
for _ in range(int(input())):
a, b = map(int, input().split())
delta = abs(a - b)
ret = 0
while not ok(ret):
ret += 1
print(ret)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR 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 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 time import *
x = int(input())
for _ in range(x):
a, b = sorted(map(int, input().split()))
diff = b - a
n, i = 0, 0
while True:
if n >= diff and (n - diff) % 2 == 0:
print(i)
break
i += 1
n += i
|
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 BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER 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 gt(a, b):
d = b - a
if d == 0:
return 0
x, i = 1, 1
while x < d or x % 2 != d % 2:
i += 1
x = i * (i + 1) // 2
return i
for _ in range(int(input())):
a, b = map(int, input().split())
if a > b:
a, b = b, a
r = gt(a, b)
print(r)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP 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 IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR 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$).
|
for nt in range(int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
continue
x = 1
i = 1
d = abs(a - b)
while x < d or x % 2 != d % 2:
i += 1
x = i * (i + 1) // 2
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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN 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 _ in range(int(input())):
a, b = map(int, input().split())
num1 = max(a, b) - min(a, b)
a = num1
val = -1
l = 1
r = a
while l < r:
mid = (l + r) // 2
if mid * (mid + 1) < a * 2:
val = mid + 1
l = mid + 1
else:
r = mid
if a == 1 or a == 0:
val = num1
while ((val + 1) * val // 2 - a) % 2 & 1:
val += 1
print(val)
|
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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP 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$).
|
import sys
input = sys.stdin.buffer.readline
def solution():
for _ in range(int(input())):
a, b = map(int, input().split())
if a < b:
a, b = b, a
k = 0
while True:
if k * (k + 1) // 2 >= a - b and (a - b) % 2 == k * (k + 1) // 2 % 2:
print(k)
break
k += 1
solution()
|
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR 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$).
|
t = int(input())
while t:
a, b = map(int, input().split())
dif = -abs(a - b)
k = 1
t = t - 1
while dif < 0:
dif += k
k = k + 1
if dif % 2 == 0:
print(k - 1)
else:
dif += k
if dif % 2 == 0:
print(k)
else:
print(k + 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 FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP 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
|
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 = []
for i in range(45000):
arr.append((i + 1) * (i + 2) // 2)
t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
d = abs(a - b)
if d == 0:
print(0)
else:
for j in range(45000):
if arr[j] >= d:
s = j + 1
c = abs(arr[j] - d)
break
if c % 2 == 0:
print(s)
elif s % 2 == 0:
print(s + 1)
else:
print(s + 2)
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER 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 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 IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR 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$).
|
for t in range(int(input())):
a, b = [int(j) for j in input().split()]
delta = abs(a - b)
z = 0
while True:
if z * (z + 1) // 2 >= delta:
if z * (z + 1) // 2 % 2 == delta % 2:
print(z)
break
z += 1
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP 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())
a, b = min(a, b), max(a, b)
d = abs(a - b)
if d == 0:
print(0)
continue
ans = 0
step = 0
for step in range(1, 10**5):
ans = ans + step
if ans >= d and (ans - d) % 2 == 0:
break
print(step)
|
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 FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP 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$).
|
t = int(input())
for i in range(t):
a, b = map(int, input().split())
mid = 0
while True:
lft = mid * (mid + 1) // 2 - a + b
if lft % 2 == 0 and 0 <= lft / 2 <= mid * (mid + 1) // 2:
break
mid += 1
print(mid)
|
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 WHILE 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 NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR 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$).
|
t = int(input())
for u in range(t):
a, b = map(int, input().split())
if a > b:
s = a - b
elif a < b:
s = b - a
else:
s = 0
k = s % 2
i = int((2 * s) ** 0.5)
p = i * (i + 1) // 2 - s
while p < 0:
i += 1
p = i * (i + 1) // 2 - s
while 1 > 0:
if k == 0:
if i % 4 == 0:
print(i)
break
elif (i + 1) % 4 == 0:
print(i)
break
else:
i += 1
elif i % 4 == 0:
i += 1
elif (i + 1) % 4 == 0:
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 IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR WHILE NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER 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(t):
a, b = map(int, input().split())
if a == b:
print("0")
continue
l = 1
s = a + b
need = max(a, b) * 2
r = 1000000
while l < r:
m = (l + r) // 2
if s + m * (m + 1) // 2 < need:
l = m + 1
else:
r = m
s += l * (l - 1) // 2
while l > 0:
s = s + l
if s >= need and s % 2 == 0:
print(l)
break
else:
l += 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR 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$).
|
from sys import stdin, stdout
t = int(input())
for i in range(t):
a, b = stdin.readline().split()
a = int(a)
b = int(b)
count = 0
sum1 = 0
diff = abs(a - b)
while sum1 < diff:
count += 1
sum1 += count
while (a + b + sum1) % 2 != 0:
count += 1
sum1 += count
print(count)
|
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR WHILE BIN_OP BIN_OP BIN_OP VAR 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$).
|
def f(n):
k = ((1 + 8 * n) ** 0.5 - 1) / 2
if int(k) == k:
k = int(k)
else:
k = int(k) + 1
if n % 2:
if k % 4 in [1, 2]:
return k
else:
while k % 4 not in [1, 2]:
k += 1
return k
elif k % 4 not in [1, 2]:
return k
else:
return k // 4 * 4 + 3
for i in " " * int(input()):
a, b = map(int, input().split())
print(f(abs(a - b)))
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER LIST NUMBER NUMBER RETURN VAR WHILE BIN_OP VAR NUMBER LIST NUMBER NUMBER VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER LIST NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR BIN_OP STRING 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())
while t > 0:
a, b = input().split(" ")
a = int(a)
b = int(b)
if a > b:
diff = a - b
else:
diff = b - a
i = 1
s = 0
c = 0
flag = False
if diff == 0:
print(0)
else:
while flag == False:
s = s + i
i = i + 1
c = c + 1
if s >= diff:
if (s - diff) % 2 == 0:
flag = True
print(c)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR 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$).
|
def ok(d):
temp = 0
for i in range(1000000000):
temp += i
if temp >= d and (temp - d) % 2 == 0:
return i
for _ in range(int(input())):
a, b = (int(x) for x in input().split())
if a == b:
print("0")
continue
d = abs(a - b)
print(ok(d))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR 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 VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR 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$).
|
t = int(input())
def minimum(a, b):
if a == b:
return 0
Found, n = False, 1
while not Found:
temp = a + n * (n + 1) // 2
if temp < b:
n += 1
elif (temp - b) % 2 == 0:
Found = True
else:
n += 1
return n
for i in range(t):
a, b = input().split()
a, b = int(a), int(b)
print(minimum(min(a, b), max(a, b)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 x in range(t):
a, b = sorted(map(int, input().split()))
for i in range(10**5):
if i * (i + 1) // 2 >= b - a and (i * (i + 1) // 2 - (b - a)) % 2 == 0:
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 NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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$).
|
from itertools import *
from sys import *
def inp():
return map(int, stdin.readline().split())
def arr_sum(arr):
arr.insert(0, 0)
return list(accumulate(arr, lambda x, y: x + y))
for i in range(int(input())):
a, b = inp()
if a == b:
print(0)
else:
ma, mi = max(a, b), min(a, b)
diff, i = ma - mi, 1
while diff > 0 or diff & 1:
diff -= i
i += 1
print(i - 1)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER WHILE 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 _ in range(t):
a, b = map(int, input().split())
cnt = 0
if a > b:
a, b = b, a
while a < b:
cnt += 1
a += cnt
while (a - b) % 2 == True:
cnt += 1
a += cnt
print(cnt)
|
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 IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR 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$).
|
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def solve():
a, b = sorted(map(int, input().split()))
if a == b:
print(0)
return
left = 0
right = 10**12
while right - left > 1:
mid = (right + left) // 2
if mid * (mid + 1) // 2 >= b - a:
right = mid
else:
left = mid
while True:
c = right * (right + 1) // 2
if (a + b + c) % 2 == 0 and (a + b + c) // 2 >= b:
print(right)
return
right += 1
t = int(input())
for i in range(t):
solve()
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP 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 NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER 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())
for i in range(t):
a, b = map(int, input().split())
x = abs(a - b)
y = 0
j = 1
count = 0
while y + j <= x:
y += j
j += 1
count += 1
z = x - y
if z == 0:
print(count)
continue
if (z - j) % 2 == 0:
count += 1
elif j % 2 == 0:
count += 2
else:
count += 3
print(count)
|
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 ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF 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$).
|
if True:
a = [1]
x = 2
while x < 44999:
a.append(a[-1] + x)
x += 1
for _ in range(int(input())):
n, x = map(int, input().split())
if n == x:
print(0)
else:
p = 1
for j in a:
if j >= abs(n - x) and j % 2 == abs(n - x) % 2:
print(p)
break
p += 1
|
IF NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP 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$).
|
for _ in range(int(input())):
a, b = map(int, input().split())
d = abs(a - b)
ans = 0
while d > 0 or -d % 2 or -d // 2 > ans:
ans += 1
d = abs(d) - ans
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 FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP 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$).
|
import sys
t = int(sys.stdin.readline())
ans_arr = []
for x in range(t):
[a, b] = [int(i) for i in sys.stdin.readline().split()]
if a == b:
ans_arr.append(str(0))
else:
ax = a
bx = b
a = max(ax, bx)
b = min(ax, bx)
d = a - b
for i in range(1, pow(10, 5) + 1):
tmp = i * (i + 1) // 2
if tmp - d >= 0 and (tmp - d) % 2 == 0 and (d + tmp) % 2 == 0:
ans_arr.append(str(i))
break
print("\n".join(ans_arr))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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$).
|
sum_first_n = [0] * 100001
for i in range(1, 100001):
sum_first_n[i] = i + sum_first_n[i - 1]
for case in range(int(input())):
a, b = [int(x) for x in input().split()]
for i in range(0, 100001):
x = a + b + sum_first_n[i]
if x % 2 == 0 and x // 2 >= a and x // 2 >= b:
print(i)
break
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR 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$).
|
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, d + 1):
if (i**2 + i) / 2 >= d:
break
for j in range(i, 100000000):
if (j * (j + 1) / 2 - d) % 2 == 0:
print(j)
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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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 _ in range(t):
a, b = map(int, input().split())
count = 0
turn = 1
for i in range(0, 50000):
x = (b - a) / 2 + i * (i + 1) / 4
y = (a - b) / 2 + i * (i + 1) / 4
if (
x % 1 == 0
and y % 1 == 0
and a + x == b + y
and x + y == i * (i + 1) / 2
and x >= 0
and y >= 0
):
ans = i
break
print(ans)
|
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 FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR 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$).
|
for tests in range(int(input())):
a, b = map(int, input().split())
diff = abs(a - b)
if diff == 0:
print(0)
continue
n = 1
k = 0
while True:
k += n
if k >= diff and (k - diff) % 2 == 0:
print(n)
break
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 BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR 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$).
|
kl = int(input())
for l in range(kl):
a, b = [int(i) for i in input().split()]
k = max(a, b) - min(a, b)
n = ((1 + 8 * k) ** 0.5 - 1) / 2
d = n - int(n)
n = int(n + 1 - (1 - d) // 1)
print(n + (1 + n % 2) * (((n - 1) % 4 // 2 + (k + 1) % 2) % 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER 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())
while t:
t -= 1
a, b = map(int, input().split())
if a > b:
a, b = b, a
cha = b - a
if cha == 0:
print(0)
continue
s, use, i = 1, 1, 2
while not (s >= cha and s % 2 == cha % 2):
use += 1
s += i
i += 1
print(use)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER 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 func1(a, b):
if a == b:
return 0
d = b - a
n = (-1 + (1 + 8 * d) ** 0.5) / 2
if n != int(n):
n = int(n) + 1
s = n * (n + 1) / 2
if (s - d) % 2 == 0:
return n
if (n + 1) % 2 == 1:
return n + 1
return n + 2
t = int(input())
k = []
for i in range(t):
lst = list(map(int, input().split()))
b = max(lst)
a = min(lst)
k.append(func1(a, b))
for i in k:
print(int(i))
|
FUNC_DEF IF VAR VAR RETURN NUMBER 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 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 VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR 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 inp():
return map(int, input().split())
def solve():
a, b = inp()
x = abs(a - b)
i = 0
s = 0
if x == 0:
return 0
while s < x or s % 2 != x % 2:
i += 1
s += i
return i
def main():
t = int(input())
while t:
print(solve())
t -= 1
main()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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$).
|
M = 1000000
class que:
def __init__(self):
self.p1 = 0
self.p2 = 0
self.st = [0] * M
def push(self, x):
self.st[self.p1] = x
self.p1 = (self.p1 + 1) % M
def front(self):
if self.p1 != self.p2:
self.p2 = (self.p2 + 1) % M
return self.st[self.p2 - 1]
n = int(input())
for ppppp in range(n):
a, b = map(int, input().split())
x = abs(a - b)
ans = 0
while x > 0:
ans += 1
x -= ans
if x < 0:
x += ans
ans -= 1
if x % 2 == 0:
if ans % 2 == 0:
ans += 3
else:
ans += 1
elif ans % 2 == 0:
ans += 1
else:
ans += 2
print(ans)
|
ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR 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 ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF 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
input = sys.stdin.readline
def main():
for _ in range(int(input())):
a, b = map(int, input().split())
i = 0
while True:
s1 = i * (i + 1) // 2
x = b - a + s1
if x % 2 == 0 and x >= 0:
x //= 2
y = s1 - x
if y >= 0:
break
i += 1
print(i)
main()
|
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF 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$).
|
import sys
def rint():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().rstrip("\n")
def oint():
return int(input())
t = oint()
for _ in range(t):
a, b = rint()
d = abs(a - b)
for i in range(10**8):
s = i * (i + 1) // 2
if (s - d) % 2:
continue
x = (s - d) // 2
if x < 0:
continue
print(i)
break
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL 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 FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF 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):
a, b = map(int, input().split())
k = -abs(a - b)
i = 0
while k < 0 or k % 2 != 0:
k -= (i - 1) * i // 2
k += i * (i + 1) // 2
i += 1
if i == 0:
print(i)
else:
print(i - 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 FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER 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$).
|
t = int(input())
for i in range(t):
line = input()
a, b = int(line.strip().split()[0]), int(line.strip().split()[1])
d = abs(a - b)
summ = 0
i = 0
while summ < d:
i += 1
summ += i
if (summ - d) % 2 == 0:
print(i)
elif i % 2 == 0:
print(i + 1)
else:
print(i + 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR 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$).
|
for _ in range(int(input())):
a, b = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
for i in range(b):
a += i
if a == b:
print(i)
break
elif a > b:
if (a - b) % 2:
print(i + 1 + i % 2)
else:
print(i)
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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP 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$).
|
N = int(input())
for i in range(N):
a, b = map(int, input().split())
diff = abs(a - b)
count = 0
while diff > 0 or diff % 2 != 0:
count += 1
diff -= count
print(count)
|
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 WHILE VAR NUMBER BIN_OP 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 i in range(int(input())):
a, b = map(int, input().split())
temp1 = max(a, b) - min(a, b)
n = 0
n = int((-1 + (1 + temp1 * 8) ** 0.5) // 2)
while True:
s = n * (2 + n - 1) // 2
temp2 = s - temp1
if temp2 >= 0 and temp2 % 2 == 0:
break
n += 1
print(int(n))
|
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 FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER 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 ok(i, diff):
sum = i * (i + 1) / 2
if sum < diff:
return False
return sum % 2 == diff % 2
for _ in range(int(input())):
a, b = map(int, input().split())
i = 0
while not ok(i, abs(a - b)):
i += 1
print(i)
|
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 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 NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP 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 x in range(t):
a = input().split()
k = []
for i in a:
k.append(int(i))
k.sort()
for i in range(10**5):
if (
i * (i + 1) // 2 >= k[1] - k[0]
and (i * (i + 1) // 2 - (k[1] - k[0])) % 2 == 0
):
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR 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$).
|
arr = [(0) for i in range(100002)]
summ = 1
for i in range(1, 100001):
arr[i - 1] = summ
summ += i + 1
t = int(input())
while t > 0:
a, b = [int(i) for i in input().split()]
if b > a:
a, b = b, a
diff = a - b
if diff == 0:
ans = 0
else:
for i in range(100000):
if arr[i] < diff:
continue
elif arr[i] == diff:
ans = i + 1
break
elif arr[i] - diff & 1 == 0:
ans = i + 1
break
print(ans)
t -= 1
|
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP 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 query in range(t):
a, b = list(map(int, input().split()))
c = abs(a - b)
left = -1
right = 10**9
while right - left > 1:
mid = (left + right) // 2
if mid * (mid + 1) // 2 >= c:
right = mid
else:
left = mid
while right * (right + 1) // 2 % 2 != c % 2:
right += 1
print(right)
|
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 VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP 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 VAR ASSIGN VAR VAR ASSIGN VAR VAR 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$).
|
def main():
tc = int(input())
for _ in range(tc):
a, b = [int(x) for x in input().split()]
if a == b:
print(0)
continue
if a > b:
a, b = b, a
cnt = 1
while True:
a += cnt
if a >= b and (a - b) % 2 == 0:
break
cnt += 1
print(cnt)
return
main()
|
FUNC_DEF 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 IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN 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$).
|
for t in range(int(input())):
a, b = map(int, input().split())
d = max(a, b) - min(a, b)
i = 0
while d % 2 or d > 0:
i += 1
d -= i
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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER 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 solve(a, b):
if a == b:
return 0
if a > b:
a, b = b, a
diff = b - a
k = 1
while diff > 0:
diff -= k
k += 1
if diff % 2 == 0:
return k - 1
else:
diff -= k
if diff % 2 == 0:
return k
else:
return k + 1
def main():
t = int(input())
for i in range(t):
d = input()
d = [int(i) for i in d.split()]
n = d[0]
a = d[1]
ans = solve(n, a)
print(ans)
main()
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF 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 VAR VAR 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$).
|
for i in range(int(input())):
a, b = map(int, input().split())
c = 1
d = max(a, b)
a = min(a, b)
b = d
while a < b:
a += c
c += 1
if (a - b) % 2 == 0:
print(c - 1)
elif c % 2 != 0:
print(c)
else:
print(c + 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER 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$).
|
t = int(input())
for _ in range(t):
a, b = [int(p) for p in input().split()]
if a > b:
temp = a
a = b
b = temp
d = b - a
for i in range(int(10**5) + 7):
x = i * (i + 1) / 4 + d / 2
if int(x) != x:
continue
y = x - d
if x >= 0 and y >= 0 and a + x == b + y:
print(i)
break
|
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 ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR 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$).
|
import sys
readline = sys.stdin.readline
def calc(x):
if x == 0:
return 0
ng = 0
ok = 10**5
while abs(ok - ng) > 1:
med = (ok + ng) // 2
S = med * (med + 1) // 2
if abs(x) <= S:
ok = med
else:
ng = med
for i in range(5):
if (ok + i) * (ok + 1 + i) // 2 % 2 == x % 2:
break
return ok + i
T = int(readline())
Ans = [None] * T
for qu in range(T):
a, b = map(int, readline().split())
Ans[qu] = calc(a - b)
print("\n".join(map(str, Ans)))
|
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE 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 BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.