description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = list(map(int, input().split()))
if m <= n:
print(n - m)
else:
memo = [0] * (m + 1)
i = 0
while i <= n:
memo[i] = n - i
i = i + 1
i = n + 1
while i <= m:
moves = None
if i % 2 == 0:
moves = 1 + memo[i // 2]
else:
moves = 2 + memo[(i + 1) // 2]
memo[i] = moves
i = i + 1
print(memo[m])
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR NONE IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def f(n, m):
count = 0
while True:
if m == n:
return count
elif m < n:
return count + (n - m)
elif m % 2 == 1:
count += 1
m += 1
else:
count += 1
m = m // 2
n, m = map(int, input().split())
print(f(n, m))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def find_path_count(x, y):
if x == y:
return 0
if x > y:
return x - y
paths = {x: 0}
count = x * y
max_t = 2 * y
cur_i = -1
results = []
while True:
new_items = {}
cur_i += 1
for t, v in paths.items():
t1 = t - 1
t2 = t * 2
if t1 == y:
res = v + 1
return res
if t2 == y:
res = v + 1
return res
if t1 not in paths and t1 > 1:
new_items[t1] = v + 1
if t2 not in paths:
if t2 < y or t2 < max_t:
if t2 > y:
count = min(count, t2 - y + v)
new_items[t2] = v + 1
paths = new_items
if cur_i >= count:
count
x, y = map(int, input().split(" "))
print(find_path_count(x, y))
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR DICT VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = list(map(lambda x: int(x), input().split()))
def twoButtons(n, m):
ans = 0
while n != m:
if m > n:
ans += 1
if m % 2 == 0:
m /= 2
else:
m += 1
elif m < n:
m += 1
ans += 1
return ans
print(twoButtons(n, m))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
initial = sys.stdin.read().split(" ")
start = int(initial[0])
end = int(initial[1])
queue = []
dic = {}
m = start
count = 0
while m < end:
m *= 2
count = count + 1
count = m - end + count
if start > end:
print(start - end)
else:
queue.append((start, 0))
while queue[0][0] != end:
if queue[0][1] > count:
break
if queue[0][0] - 1 >= 0 and queue[0][0] <= m and not queue[0][0] - 1 in dic:
queue.append((queue[0][0] - 1, queue[0][1] + 1))
dic[queue[0][0] - 1] = queue[0][1]
if queue[0][0] * 2 <= m and not queue[0][0] * 2 in dic:
queue.append((queue[0][0] * 2, queue[0][1] + 1))
dic[queue[0][0] * 2] = queue[0][1]
queue.pop(0)
print(queue[0][1])
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER NUMBER VAR IF VAR NUMBER NUMBER VAR IF BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a, b = map(int, input().split())
cont = 0
while True:
if a >= b:
cont += a - b
break
else:
cont += 1
if a * 2 == b:
break
else:
b = [b // 2, b + 1][b % 2]
print(cont)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
n, m = (int(i) for i in sys.stdin.readline().split())
factor_count = 0
factor = 1
to_add = 0
while n < m:
n *= 2
factor *= 2
factor_count += 1
to_add_total = 0
to_add = n - m
temp_factor = factor
while to_add > 0 and temp_factor > 0:
to_add_total += to_add // temp_factor
to_add -= temp_factor * (to_add // temp_factor)
temp_factor //= 2
to_add_total += to_add
print(factor_count + to_add // factor + to_add_total)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if m <= n:
print(n - m)
else:
for i in range(1, m // n + 2):
if n * 2**i >= m:
a = i
break
if n * 2**a == m:
print(a)
else:
ncount = 1
while n != m:
if n > m / 2**a > n - 1:
n *= 2
ncount += 1
a -= 1
b = 0
elif n - 1 > m / 2**a:
n -= 1
ncount += 1
b = 0
else:
b = 1
break
if b == 0:
print(ncount)
else:
print(ncount + a)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def bfs(n, m):
queue = [[n, 0]]
d = {}
x = 2 * m
while queue:
q = queue.pop(0)
v, k = q[0], q[1]
if v == m:
return k
e = v - 1
if e > 0:
if d.get(e) == None:
d[e] = 0
queue.append([e, k + 1])
e = v * 2
if e <= x:
if d.get(e) == None:
d[e] = 0
queue.append([e, k + 1])
n, m = map(int, input().split())
if n >= m:
print(n - m)
else:
print(bfs(n, m))
|
FUNC_DEF ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def two_buttons(start, end):
cache = get_cache(start)
temp = start + 1
while end not in cache:
if temp % 2 == 0:
cache[temp] = 1 + cache[temp / 2]
else:
cache[temp] = 2 + cache[(temp + 1) / 2]
temp += 1
return cache[end]
def get_cache(start):
cache = {i: (start - i) for i in range(1, start)}
cache[start] = 0
return cache
n, m = [int(e) for e in input().split()]
print(two_buttons(n, m))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a, b = [int(x) for x in input().split()]
count = 0
if b > a:
while b != a:
if b < a:
count += a - int(b)
b = a
break
count += 1
if b % 2:
b += 1
else:
b = b / 2
print(count)
else:
print(a - b)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(a) for a in input().split()]
amount = 0
if n > m:
amount = n - m
else:
while m > n:
if m % 2 == 0:
m //= 2
else:
m += 1
amount += 1
amount += n - m
print(amount)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def mi(m, n):
if m == n:
return 0
if m > n:
return m - n
if m <= 0 and n > 0:
return -1
if n % 2 == 1:
return 1 + mi(m, n + 1)
else:
return 1 + mi(m, n // 2)
m, n = map(int, input().split())
print(mi(m, n))
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def f():
ans = 0
n, m = map(int, input().split())
while n != m:
if n > m:
ans += n - m
break
else:
if m % 2 == 0:
m /= 2
else:
m += 1
ans += 1
print(int(ans))
f()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
[n, m] = [int(_) for _ in input().split()]
ans = 0
if n > m:
ans = n - m
else:
lis = [(-1) for _ in range(2 * m + 1)]
count = 0
lis[n] = count
stepset = {n}
while lis[m] == -1:
count += 1
tempset = set([])
for x in stepset:
y = 2 * x
if 0 < y < 2 * m and lis[y] == -1:
tempset.add(y)
lis[y] = count
y = x - 1
if 0 < y < 2 * m and lis[y] == -1:
tempset.add(y)
lis[y] = count
stepset = tempset
ans = lis[m]
print(ans)
|
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n > m:
print(n - m)
else:
if m % 2 == 1:
m += 1
r = 1
else:
r = 0
nn, mm, mini = n, m, 0
a = [m]
mini = 1000000
while a[-1] != 1:
if mm % 2 == 1:
mm += 1
l = mm // 2
a.append(l)
mm = mm // 2
for i in range(len(a) - 1, -1, -1):
if a[i] <= n:
k = a[i]
else:
break
i += 1
r += n - k
while k != m:
k *= 2
r += 1
if k not in a:
k -= 1
r += 1
print(r)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
ans = 0
while 2 * n < m:
n = 2 * n
ans += 1
if n < m:
if m == 2 * n:
ans += 1
else:
n = 2 * n
ans += 1
u = ans + 1
while n != m:
r = u
x = 0
while r > 0 and n > m:
l = 2**x
if n - l < m:
l = 2 ** (x - 1)
n -= l
break
if n - l == m or r == 1:
n = n - l
break
x += 1
r -= 1
ans += 1
if n == m:
break
elif n > m:
ans = n - m
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
x, y = map(int, input().split())
c = 0
for i in range(10000):
if y > x:
if y % 2 != 0:
y = y + 1
c = c + 1
else:
y = y // 2
c = c + 1
elif y < x:
c = c + (x - y)
print(c)
break
else:
print(c)
break
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def sol(a, b):
f = True
c = 0
r = []
if b % 2:
c += 1
b += 1
while b > 0 and not b % 2:
r = [b // 2] + r
b //= 2
if a < r[0]:
return c + sol(a, r[0]) + sol(r[0], 2 * r[-1])
else:
for i in range(len(r)):
if a == r[i]:
c += len(r) - i
f = False
break
elif a < r[i]:
c += a - r[i - 1]
c += len(r) - (i - 1)
f = False
break
if f:
c += a - r[-1]
c += 1
return c
x, y = map(int, input().split())
if y <= x:
print(x - y)
else:
print(sol(x, y))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
t = [1] * m
d = [(n, 0)]
x = n + m
while d:
n, s = d.pop(0)
if n >= m:
x = min(x, s + n - m)
elif t[n]:
t[n] = 0
d.append((2 * n, s + 1))
if n > 1:
d.append((n - 1, s + 1))
print(x)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def find_presses(n, m):
presses = 0
while n < m:
if m % 2 == 0:
m //= 2
else:
m += 1
presses += 1
print(presses + (n - m))
n, m = map(int, input().split(" "))
find_presses(n, m)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
q = 0
while n != m:
m = [m // 2, m + 1][m & 1 or m < n]
q += 1
print(q)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(x) for x in input().split()]
step = 0
if m == n or m < n:
step = n - m
else:
while m > n:
if m % 2 == 0:
m = m / 2
step += 1
else:
m = (m + 1) / 2
step += 2
if m < n or m == n:
step += n - m
print(int(step))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
ans = 0
if n >= m:
print(n - m)
else:
while n != m:
if m < n:
ans += n - m
break
elif m % 2 == 0:
m = m // 2
ans += 1
else:
m += 1
ans += 1
if n == m:
break
m = m // 2
ans += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n == m:
print(0)
if n > m:
num = n - m
print(num)
def bfs(nohdepartida, nohdechegada):
nivel = []
for i in range(10002):
nivel.append(-1)
fila = []
fila.append(n)
nivel[n] = 0
while len(fila) > 0:
nohtop = fila.pop()
if nohtop == m:
print(nivel[nohtop])
break
if 2 * nohtop <= 10000:
if nivel[2 * nohtop] == -1:
nivel[2 * nohtop] = nivel[nohtop] + 1
fila.insert(0, 2 * nohtop)
if nohtop > 1:
if nivel[nohtop - 1] == -1:
nivel[nohtop - 1] = nivel[nohtop] + 1
fila.insert(0, nohtop - 1)
if m > n:
bfs(n, m)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
inicial, final = list(map(int, input().split()))
if inicial >= final:
print(int(inicial - final))
else:
retorno = 0
aux = final
while aux > inicial:
if not aux % 2 == 0:
aux += 1
retorno += 1
aux = aux / 2
retorno += 1
retorno += inicial - aux
print(int(retorno))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
ans = 0
while n != m:
while n > m:
m += 1
ans += 1
if m % 2 == 0 and n != m:
m //= 2
ans += 1
elif n != m and m % 2:
m += 1
m //= 2
ans += 2
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = list(map(int, input().split()))
cnt = 0
while n < m:
if m % 2 == 1:
m += 1
cnt += 1
else:
m //= 2
cnt += 1
cnt += abs(m - n)
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
n, m = idata()
if n >= m:
print(n - m)
else:
n1, m1 = n, m
count = 0
while n1 <= m1 // 2:
if m1 % 2 == 1:
m1 += 1
count += 1
m1 //= 2
count += 1
if n1 == m1:
print(count)
else:
print(count + n1 - m1 // 2 + 1)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(p) for p in input().split()]
sum = 0
if n >= m:
sum += n - m
else:
sum = 0
while m > n:
if m % 2 == 0:
sum += 1
m = m // 2
elif m % 2 == 1:
sum += 2
m = (m + 1) // 2
sum += n - m
print(sum)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def num_steps(given, ideal):
steps = 0
while given < ideal:
if ideal % 2 == 0:
ideal = ideal / 2
else:
ideal += 1
steps += 1
return int(steps + (given - ideal))
inputs = [int(num) for num in input().split()]
n = inputs[0]
m = inputs[1]
result = num_steps(n, m)
print(result)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR 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 VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
class Queue:
def __init__(self):
self.list = []
def push(self, value):
self.list.append(value)
def pop(self):
return self.list.pop(0)
def top(self):
return self.list[0]
def empty(self):
return len(self.list) == 0
n, m = map(int, input().split())
MAX_VALUE = 2 * max(n, m)
q = Queue()
q.push(n)
count = [(0) for i in range(MAX_VALUE + 1)]
while q.top() != m:
u = q.pop()
if u - 1 >= 0 and count[u - 1] == 0:
count[u - 1] = count[u] + 1
q.push(u - 1)
if u * 2 <= MAX_VALUE and count[u * 2] == 0:
count[u * 2] = count[u] + 1
q.push(u * 2)
print(count[m])
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def answer2(N, M, count):
if M <= N:
return count + N - M
if M % 2 != 0:
count += 1
M += 1
return answer2(N, M // 2, count + 1)
N, M = map(int, input().split())
print(answer2(N, M, 0))
|
FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if m < n:
print(n - m)
elif m == n:
print(0)
else:
count = 0
while m > n:
if m & 1:
m = int((m + 1) / 2)
count += 1
else:
m = int(m / 2)
first = 1
count += 1
count += abs(m - n)
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def f(a, b):
if b <= a:
return a - b
return 1 + b % 2 + f(a, (b + 1) // 2)
a, b = map(int, input().split())
print(f(a, b))
|
FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
inS = input()
nums = [int(i) for i in inS.split(" ")]
n = nums[0]
m = nums[1]
dp_arr = [99999] * (10**4 + 1)
dp_arr[n] = 0
for i in range(n, 0, -1):
dp_arr[i] = n - i
for i in range(1, len(dp_arr)):
if i + 1 < len(dp_arr):
dp_arr[i] = min(dp_arr[i], dp_arr[i + 1] + 1)
if i * 2 < len(dp_arr):
dp_arr[i * 2] = min(dp_arr[i * 2], dp_arr[i] + 1)
print(dp_arr[m])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
n, m = map(int, input().split())
count = 0
if m <= n:
print(n - m)
sys.exit(0)
while n != m:
if n < m:
if m % 2 == 0:
m = m / 2
else:
m = m + 1
else:
break
count = count + 1
print(int(n - m + count))
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
visit = [0] * (10**6 + 1)
ls = []
ls.append((n, 0))
while len(ls):
cur = list(ls.pop(0))
if cur[0] == m:
print(cur[1])
break
visit[cur[0]] = 1
if cur[0] - 1 > 0 and visit[cur[0] - 1] == 0:
ls.append((cur[0] - 1, cur[1] + 1))
if cur[0] * 2 < 10**5 and visit[cur[0] * 2] == 0:
ls.append((cur[0] * 2, cur[1] + 1))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = input(" ").split()
n = int(n)
m = int(m)
n, m = m, n
n = n
m = m
count = 0
while n - m != 0:
if n < m or n == m:
count = count + m - n
n = 0
m = 0
break
elif n > m:
if n % 2 == 0:
n = n / 2
count = count + 1
m = m
else:
n = n + 1
count = count + 1
m = m
print(int(count))
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
from sys import stdin
def main():
n, m = stdin.readline().split(" ")
print(solve(int(n), int(m)))
class Node:
def __init__(self, data, depth=0, l=None, r=None):
self.data = data
self.depth = depth
self.left = l
self.right = r
def solve(n, m):
queue = []
seen = set()
queue.append(Node(n))
while len(queue) >= 0:
temp = queue.pop(0)
if temp.data == m:
return temp.depth
timesTwo = temp.data * 2
if timesTwo not in seen and temp.data < m:
temp.left = Node(timesTwo, temp.depth + 1)
queue.append(temp.left)
seen.add(timesTwo)
minusOne = temp.data - 1
if minusOne not in seen and minusOne >= 0:
temp.right = Node(minusOne, temp.depth + 1)
queue.append(temp.right)
seen.add(minusOne)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF NUMBER NONE NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a, b = list(map(int, input().split()))
if a > b:
print(a - b)
else:
c = 0
while a < b:
if a != b and b % 2 == 0:
b = b // 2
c += 1
else:
b += 1
c += 1
c = a - b + c
print(c)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
n, m = invr()
c = 0
while n != m:
if m < n:
m += 1
elif m % 2 == 0:
m /= 2
elif m % 2 == 1:
m = (m + 1) / 2
c += 1
c += 1
print(c)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
def minPress(startNumber, endNumber):
numberList = []
visited = {}
numberList.append([startNumber, 0])
visited[startNumber] = 0
minCount = sys.maxsize
while len(numberList) != 0:
nextVal = numberList.pop()
if nextVal[0] >= endNumber:
tempCount = nextVal[1] + nextVal[0] - endNumber
if tempCount < minCount:
minCount = tempCount
else:
if nextVal[0] * 2 <= endNumber * 2 and (
nextVal[0] * 2 not in visited
or visited[nextVal[0] * 2] >= nextVal[1] + 1
):
visited[nextVal[0] * 2] = nextVal[1] + 1
numberList.append([nextVal[0] * 2, nextVal[1] + 1])
if nextVal[0] - 1 > 1 and (
nextVal[0] - 1 not in visited
or visited[nextVal[0] * 2] >= nextVal[1] + 1
):
visited[nextVal[0] - 1] = nextVal[1] + 1
numberList.append([nextVal[0] - 1, nextVal[1] + 1])
return minCount
startNumber, endNumber = [int(x) for x in sys.stdin.readline().split()]
print(minPress(startNumber, endNumber))
|
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
def problem2(n, m):
if n == m:
return "0"
cont = 0
while n != m:
if n > m:
return cont + (n - m)
if m % 2 == 0:
m = m // 2
else:
m += 1
cont += 1
if cont > 60:
break
return cont
print(problem2(n, m))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
ch = input()
l = ch.split(" ")
n = int(l[0])
m = int(l[1])
nb = 0
if n > m:
nb = n - m
else:
a = n
i = 0
while a < m:
i = i + 1
a = 2 * a
j = a - m
c = 0
nb = i
while j >= 2 and c < i:
nb = nb + j % 2
j = j // 2
c = c + 1
nb = nb + j
print(nb)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def find_path_count(x, y):
if x == y:
return 0
paths = {x: 0}
count = x * y
max_t = 2 * y
cur_i = -1
results = []
while True:
new_items = {}
cur_i += 1
for t, v in paths.items():
temps = t - 1, t * 2
for temp in temps:
if temp == y:
return v + 1
if temp not in paths:
if temp > 1:
if temp > y:
count = min(count, temp - y + v + 1)
continue
new_items[temp] = v + 1
paths = new_items
if cur_i >= count:
return count
x, y = map(int, input().split(" "))
print(find_path_count(x, y))
|
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR DICT VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
line = input().split()
n = int(line[0])
m = int(line[1])
a = []
a += [n]
i = 1
node = i
level = 1
np = 0
visit = [0] * 10001
while len(a) > 0:
if a[0] == m:
print(visit[a[0]])
break
else:
temp = a[0] * 2
if temp < 10001 and visit[temp] == 0:
a += [a[0] * 2]
visit[temp] = visit[a[0]] + 1
temp = a[0] - 1
if temp > 0 and visit[temp] == 0:
a += [a[0] - 1]
visit[temp] = visit[a[0]] + 1
a.pop(0)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a, b = map(int, input().split())
c = 0
while a != b:
if a > b:
c += a - b
a = b
elif b % 2:
b = (b + 1) // 2
c += 2
else:
b //= 2
c += 1
print(c)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a = list(map(int, input().split()))
start = a[1]
end = a[0]
answer = 0
while end != start:
if start < end:
answer += end - start
break
if start % 2 == 0:
start //= 2
else:
start += 1
answer += 1
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
count = 0
m, n = [int(x) for x in input().split()]
queue = [(m, 0)]
visited = set([m])
minstep = float("inf")
while queue:
num, step = queue.pop(0)
if num == n:
if step < minstep:
minstep = step
if num > n:
adder = num - n
queue.append((n, step + adder))
else:
for adder in [lambda x: x - 1, lambda x: x * 2]:
ne = adder(num)
if ne == n or ne not in visited and ne > 0:
queue.append((ne, step + 1))
visited.add(ne)
print(minstep)
|
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
vhod = input()
vhod_list = vhod.split()
do = int(vhod_list[0])
posle = int(vhod_list[1])
kostilist = []
uroven = 0
fixprice = 0
maxuroven = 0
fixkostil = 0
shagi = 0
def search(do):
global kostilist
it = 0
while do < kostilist[it]:
it += 1
if do == kostilist[it]:
return do
if it == 0:
return kostilist[0]
if do - kostilist[it] < do * 2 - kostilist[it]:
return kostilist[it]
else:
return kostilist[it - 1]
def recc(do, posle, kostilist):
it = 0
global shagi
while do != kostilist[it]:
it += 1
if it == 0:
return -1
while do != posle:
if it > 0:
if do * 2 == kostilist[it - 1]:
shagi += 1
do *= 2
it -= 1
else:
shagi += 2
do *= 2
do -= 1
it -= 1
if it == 0:
if do * 2 == posle:
shagi += 1
do = do * 2
else:
shagi += 2
do = do * 2 - 1
return do
def rekursivnoelezhat(do, posle):
global kostilist
global shagi
fixprice = 0
while do != posle:
fixprice = search(do)
if fixprice < do:
while do != fixprice:
do -= 1
shagi += 1
elif fixprice == do:
if fixprice == kostilist[0]:
shagi += 1
do *= 2
else:
do *= 2
shagi += 1
while do != fixprice:
do -= 1
shagi += 1
if do == posle:
return
kostil = recc(do, posle, kostilist)
if kostil == -1:
shagi += 1
do *= 2
if do == posle + 1:
shagi += 1
return
elif kostil == posle:
return
else:
do = kostil
shagi += 1
do *= 2
def lezhat(do, posle):
global kostilist
global shagi
novoeposle_1 = 0
if posle % 2 == 0:
novoeposle_1 = posle
while novoeposle_1 != 1:
kostilist.append(int(novoeposle_1 / 2))
novoeposle_1 /= 2
if novoeposle_1 == 1:
break
if novoeposle_1 % 2 != 0:
novoeposle_1 += 1
else:
novoeposle_1 = posle + 1
while novoeposle_1 != 1:
kostilist.append(int(novoeposle_1 / 2))
novoeposle_1 /= 2
if novoeposle_1 == 1:
break
if novoeposle_1 % 2 != 0:
novoeposle_1 += 1
it = 0
if do > posle:
while do > posle:
do -= 1
it += 1
print(it)
elif do == posle:
print(0)
else:
rekursivnoelezhat(do, posle)
print(shagi)
lezhat(do, posle)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR NUMBER RETURN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR RETURN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN IF VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
color = {}
dist = {}
def bfs(start):
st = [start]
color[start] = 1
dist[start] = 0
while st:
v = st.pop(0)
if v > 1 and v - 1 not in color.keys():
color[v - 1] = 1
dist[v - 1] = dist[v] + 1
st.append(v - 1)
if v < m and v * 2 not in color.keys():
color[v * 2] = 1
dist[v * 2] = dist[v] + 1
st.append(v * 2)
if m in color.keys():
print(dist[m])
break
bfs(n)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
s = 0
if n > m:
print(n - m)
else:
while n != m:
if m % 2 == 0 and m / 2 > n / 2:
m = m / 2
else:
m = m + 1
s = s + 1
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def minpath(n, m, visited, q, d):
while len(q) != 0:
x = q.pop(0)
visited[x] = True
a = x * 2
if x != 1:
b = x - 1
else:
b = a
if a in visited:
d[a] = min(d[a], d[x] + 1)
else:
if a <= 10**4:
q.append(a)
d[a] = d[x] + 1
visited[a] = True
if b in visited:
d[b] = min(d[b], d[x] + 1)
else:
if b <= 10**4:
q.append(b)
d[b] = d[x] + 1
visited[b] = True
if m in visited:
return d[m]
n, m = list(map(int, input().split()))
visited = {}
d = {}
q = []
if m <= n:
print(n - m)
else:
q.append(n)
d[n] = 0
print(minpath(n, m, visited, q, d))
|
FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
class Node(object):
def __init__(self, val, level):
self.val = val
self.level = level
def solve(m, n):
if m >= n:
return m - n
queue = [Node(m, 0)]
visited = set([m])
count = 0
while queue:
item = queue.pop(0)
if item.val == n:
return item.level
if item.val - 1 >= 0 and item.val - 1 not in visited:
visited.add(item.val - 1)
queue.append(Node(item.val - 1, item.level + 1))
if item.val < n and item.val * 2 not in visited:
visited.add(item.val * 2)
queue.append(Node(item.val * 2, item.level + 1))
n, m = [int(val) for val in input().split(" ")]
print(solve(n, m))
|
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
from sys import stdin
inp = list(map(lambda s: s.strip(), stdin.readlines()))
n, m = map(lambda x: int(x), inp[0].split())
def solve(n, m):
if m < n:
return n - m
if m == n:
return 0
if m % 2 == 1:
return 2 + solve(n, m // 2 + 1)
return 1 + solve(n, m // 2)
print(solve(n, m))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
lst = [int(i) for i in input().split()]
n = lst[0]
m = lst[1]
class Node:
def __init__(self, val):
self.val = val
self.adj = []
nodes = []
max_node = 2 * max(m, n) + 1
for i in range(0, (max_node - 1) * 2 + 2):
nodes.append(Node(i))
if max_node > 1:
nodes[1].adj.append(nodes[2])
for i in range(2, max_node):
nodes[i].adj.append(nodes[i - 1])
nodes[i].adj.append(nodes[2 * i])
visited = set()
queue = [(nodes[n], 0)]
path_len = 0
while len(queue) != 0:
node, path_len = queue.pop(0)
visited.add(node)
if node.val == m:
break
for adj in node.adj:
if adj not in visited:
queue.append((adj, path_len + 1))
print(path_len)
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def main():
n, m = map(int, input().split())
print(rec(n, m))
def rec(n, m):
if m <= n:
return n - m
elif m % 2:
return rec(n, m + 1) + 1
else:
return rec(n, m // 2) + 1
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = list(map(int, input().split()))
l = 0
if m == n:
print("0")
elif m < n:
print(n - m)
else:
while m > n:
if m % 2 == 0:
l += 1
m /= 2
else:
l += 1
m += 1
print(int(l + n - m))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(x) for x in input().split()]
if n >= m:
print(n - m)
if n < m:
a = m
red = 0
blue = 0
while a > n:
if a % 2 == 0:
red += 1
a = int(a / 2)
else:
red += 1
blue += 1
a = int((a + 1) / 2)
blue += n - a
print(blue + red)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
sys.setrecursionlimit(10000)
def insertion(G, A):
while A != []:
s = A[0][0]
i = A[0][1]
del A[0]
if s > 1 and (not s - 1 in G.keys() or G[s - 1] > i):
G[s - 1] = i
A = A + [[s - 1, i + 1]]
if 2 * s <= 10000 and (not 2 * s in G.keys() or G[2 * s] > i):
G[2 * s] = i
A = A + [[2 * s, i + 1]]
return G
n, m = map(int, input().split())
G = dict()
G[n] = 0
A = [[n, 1]]
G = insertion(G, A)
print(G[m])
|
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF WHILE VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR LIST LIST BIN_OP NUMBER VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
Q = []
sz = 0
inf = 1000000009
Q.append(n)
D = [inf] * 20004
D[n] = 0
while sz < len(Q):
x = Q[sz]
sz += 1
if x + x <= 20000 and D[x + x] == inf:
D[x + x] = D[x] + 1
Q.append(x + x)
if x - 1 >= 1 and D[x - 1] == inf:
D[x - 1] = D[x] + 1
Q.append(x - 1)
print(D[m])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(k) for k in input().split()]
cnt = 0
while n != m:
if m > n:
if m % 2 == 0:
m = m // 2
cnt += 1
else:
m += 1
cnt += 1
else:
cnt += n - m
n = m
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def shortest_path(n, m):
queue = [n]
visited = {}
depth = {n: 0}
while len(queue) != 0:
num = queue.pop()
if num == m:
return depth[num]
if num - 1 > 0 and not visited.get(num - 1, False):
queue.insert(0, num - 1)
visited[num - 1] = True
depth[num - 1] = depth[num] + 1
if num < m and not visited.get(num * 2, False):
queue.insert(0, num * 2)
visited[num * 2] = True
depth[num * 2] = depth[num] + 1
n, m = list(map(lambda s: int(s), input().split(" ")))
print(shortest_path(n, m))
|
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR DICT VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n > m:
print(n - m)
exit()
r, c = 0, float("inf")
while m != 1 and m != n:
if m % 2:
r += 1
m += 1
else:
r += 1
m //= 2
if m < n:
c = min(c, r + n - m)
if m == n:
print(r)
else:
print(c)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING WHILE VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
inp = input().split(" ")
n = int(inp[0])
m = int(inp[1])
move = 0
while True:
if n >= m:
print(move + (n - m))
exit(0)
if m % 2 == 0:
m //= 2
move += 1
else:
m = (m + 1) // 2
move += 2
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n >= m:
print(n - m)
else:
dp = [float("inf")] * (2 * (m + 1))
dp[n] = 0
i = n - 1
while i >= 0:
dp[i] = dp[i + 1] + 1
i -= 1
for i in range(1, m + 1):
dp[2 * i] = min(dp[2 * i], dp[i] + 1)
if dp[2 * i - 1] == float("inf"):
dp[2 * i - 1] = dp[2 * i] + 1
print(dp[m])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
inputs = input()
split = inputs.split(" ")
display = int(split[0])
goal = int(split[1])
visited = [display]
queue = [(display, 1)]
def main():
while queue:
s, d = queue.pop(0)
neighbors = []
if s > 0:
neighbors.append(s - 1)
if s <= goal:
neighbors.append(s * 2)
for neighbor in neighbors:
if neighbor == goal:
print(d)
return
if neighbor in visited:
continue
visited.append(neighbor)
queue.append((neighbor, d + 1))
if display == goal:
print(0)
else:
main()
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n >= m:
print(n - m)
else:
a = set()
a.add(n)
ans = 0
while m not in a:
b = set()
for i in a:
if i - 1 >= n / 3:
b.add(i - 1)
if 2 * i < 2 * m:
b.add(2 * i)
ans += 1
a = b.difference(a)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
if n >= m:
print(n - m)
else:
ans1, ans2, tmp_m, tmp_n = 0, 0, m, n
while tmp_n < m:
tmp_n *= 2
ans1 += 1
ans1 += tmp_n - m
while tmp_m > n:
if tmp_m & 1:
tmp_m += 1
else:
tmp_m //= 2
ans2 += 1
ans2 += n - tmp_m
print(min([ans1, ans2]))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, k = input().split()
n = int(n)
k = int(k)
if n > k:
print(n - k)
elif n == k:
print(n - k)
else:
pas = 0
while k > n:
if k & 1:
k += 1
k //= 2
pas += 2
else:
k //= 2
pas += 1
if k < n:
pas += n - k
print(pas)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(next) for next in input().split()]
if m <= n:
print(n - m)
else:
answer = 0
while n < m:
if m % 2 == 1:
m += 1
answer += 1
m //= 2
answer += 1
if n == m:
print(answer)
else:
ans = 10000000000
nn = n
i = 0
while nn > 0:
tmp = i + answer
while nn < m:
nn *= 2
tmp += 1
tmp += nn - m
ans = min(ans, tmp)
i += 1
nn = n - i
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def best_value(value):
if value % 2 == 0:
return int(value / 2)
else:
return value + 1
n, m = [int(x) for x in input().split()]
if n >= m:
print(n - m)
else:
bestShot = m
count = 0
while bestShot > n:
bestShot = best_value(bestShot)
count += 1
count += n - bestShot
print(count)
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def main():
read_many = lambda type_: list(map(type_, input().split()))
n, m = read_many(int)
press = 0
while m > n:
m = m + 1 if m % 2 == 1 else m // 2
press += 1
result = press + n - m
print(result)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def getVals(type=str):
return list(map(type, input().split()))
def solve(x, y):
if x >= y:
return x - y
ans = 0
while y != x:
if x < y:
if y & 1:
y += 1
else:
y >>= 1
else:
y += 1
ans += 1
return ans
x, y = getVals(int)
print(solve(x, y))
|
FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write
def input():
return fast_reader().strip()
def print(*argv):
fast_writer(" ".join(str(i) for i in argv))
fast_writer("\n")
for _ in range(1):
n, m = map(int, input().split())
ans = 0
while m > n:
if m % 2 == 0:
m = m // 2
else:
m += 1
ans += 1
print(ans + (n - m))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def Solve(n, m):
moves = 0
while True:
if m < n:
return moves + n - m
if m % 2 == 0:
m = int(m / 2)
else:
m += 1
moves += 1
if m == n:
return moves
def main():
n, m = map(int, input().split())
print(Solve(n, m))
main()
|
FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
input = sys.stdin.readline
n, m = map(int, sys.stdin.readline().split())
res = 0
while m != n:
if m % 2 == 1 or m < n:
m += 1
else:
m = m // 2
res += 1
print(res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
class SiteGame:
def __init__(self, n, m):
self.n = n
self.m = m
opirationNumber = 0
if m <= n:
opirationNumber += n - m
print(opirationNumber)
return
while True:
if m % 2 == 1:
m += 1
opirationNumber += 1
m = m // 2
opirationNumber += 1
if m <= n:
break
opirationNumber += n - m
print(opirationNumber)
SiteGame(n, m)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
ans = [-1] * (n + m)
for i in range(1, n + 1):
ans[i] = n - i
for i in range(n + 1, m + 1):
if i % 2 == 0:
ans[i] = 1 + ans[i // 2]
else:
ans[i] = 2 + ans[(i + 1) // 2]
print(ans[m])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
x, y = [int(a) for a in input().split()]
z = 0
if y < x:
print(x - y)
quit()
else:
while y > x:
if y % 2 == 0:
y = y / 2
z += 1
else:
y += 1
z += 1
print(int(abs(z + x - y)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
r = lambda: map(int, input().split())
n, m = r()
def func_exe(n, m):
if n > m:
return n - m
elif m == n:
return 0
elif m % 2 == 0:
return 1 + func_exe(n, int(m / 2))
else:
return 1 + func_exe(n, int(m + 1))
print(func_exe(n, m))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(i) for i in input().split()]
count = 0
if n > m:
print(n - m)
else:
while n < m:
if m % 2 == 0:
m /= 2
count += 1
else:
m += 1
count += 1
count = int(abs(count + (n - m)))
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
begin, want = map(int, input().split())
diff = want - begin
if diff > 0:
steps = 0
while want != begin:
steps += 1
if want > begin:
if want % 2 == 0:
want = want / 2
else:
want += 1
elif want < begin:
want += 1
print(steps)
elif diff < 0:
print(abs(diff))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
start, target = map(int, input().split())
def recur(s, t, steps):
if s > t:
return steps + s - t
elif s == t:
return steps
elif t & 1:
return recur(s, t + 1, steps + 1)
else:
return recur(s, t // 2, steps + 1)
print(recur(start, target, 0))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR IF BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = map(int, input().split())
distance = [-1] * 10000001
distance[n] = 0
q = [n]
while len(q) > 0:
u = q.pop(0)
v = u * 2
x = u - 1
if distance[v] == -1 and v < m * 2:
distance[v] = distance[u] + 1
q.append(v)
if distance[x] == -1 and x > 0:
distance[x] = distance[u] + 1
q.append(x)
print(distance[m])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
inlet = input().split(" ")
n, m = int(inlet[0]), int(inlet[1])
cont = 0
while m > n:
if m // 2 != m / 2:
cont += 1
m += 1
m = m // 2
cont += 1
if n >= m:
print(n - m + cont)
exit()
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
def read_input():
inp = []
for line in sys.stdin:
d = line.split(" ")
inp.append(int(d[0]))
inp.append(int(d[1]))
return inp
def __read_input():
return [2, 10]
def solve(n, m):
i = 0
d = {}
x = {}
d.update({i: [n]})
x.update({n: i})
while x.get(m) == None or len(d[i]) == 0:
d.update({(i + 1): []})
for k in d[i]:
if k - 1 > 0 and x.get(k - 1) == None:
d[i + 1].append(k - 1)
x.update({(k - 1): i})
if k < m and x.get(2 * k) == None:
d[i + 1].append(2 * k)
x.update({(2 * k): i})
i += 1
print(i)
inp = read_input()
solve(inp[0], inp[1])
|
IMPORT FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT EXPR FUNC_CALL VAR DICT VAR LIST VAR EXPR FUNC_CALL VAR DICT VAR VAR WHILE FUNC_CALL VAR VAR NONE FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR DICT BIN_OP VAR NUMBER LIST FOR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NONE EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR DICT BIN_OP VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR DICT BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = list(map(int, input().split()))
if n == m:
print(0)
exit()
x = set()
q = [(n, 0)]
s = 0
while len(q):
w = q.pop(0)
a = w[0] - 1, w[1] + 1
b = (w[0] * 2, w[1] + 1) if w[0] < m else (w[0] - 1, w[1] + 1)
if a[0] == m:
print(a[1])
break
if b[0] == m:
print(b[1])
break
if a[0] not in x and a[0] > 1:
x.add(a[0])
q.append(a)
if b[0] not in x and 0 < b[0]:
x.add(b[0])
q.append(b)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
a = [int(x) for x in input().split()]
start = a[0]
end = a[1]
counter = 0
total = start
while total < end:
total *= 2
counter += 1
diff = total - end
coeffs = []
coeff = 1
for i in range(0, counter + 1):
coeffs.append(coeff)
coeff *= 2
needed = []
for i in range(len(coeffs) - 1, -1, -1):
needed.append(int(diff / coeffs[i]))
diff -= needed[-1] * coeffs[i]
print(sum(needed) + counter)
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(s) for s in input().split()]
MAX_LIMIT = 10000
def get_min_clicks():
inputs, clicks = {n}, 0
while True:
new_inputs = set()
for element in inputs:
if element == m:
return clicks
if element > 0:
new_inputs.add(element - 1)
if element < m:
new_inputs.add(element * 2)
under_target = [el for el in new_inputs if el < m]
over_target = [el for el in new_inputs if el >= m]
if len(over_target) > 1:
over_target = [min(over_target)]
inputs = set()
inputs = inputs.union(under_target).union(over_target)
clicks += 1
print(get_min_clicks())
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
nums = [int(i) for i in input().split()]
a, b = nums
def counter(n, m):
count = 0
if m % 2:
count += 1
m += 1
while m != n:
if m > n:
if m % 2 == 0:
m //= 2
else:
m += 1
count += 1
else:
count += n - m
m = n
return count
print(counter(a, b))
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
from sys import stdout
def main():
from sys import stdout
n, m = map(int, input().split())
res = 0
while n != m:
if n >= m:
res += n - m
n = m
else:
if m % 2 == 1:
m += 1
res += 1
m = m / 2
res += 1
stdout.write(str(int(res)))
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
import sys
def read_from_stdin():
n, m = input().split()
return int(n), int(m)
def write_to_stdout(res):
sys.stdout.write("%d\n" % res)
def half_the_number(number, n):
count = 0
while number % 2 == 0 and number > n:
new_number = number / 2
if int(new_number) * 2 == number:
number = int(new_number)
count += 1
else:
break
return number, count
def get_answer(n, m):
res = n
count = 0
while m != n:
if m % 2 == 0:
m, count_half = half_the_number(m, n)
count += count_half
if m < n:
count += n - m
break
else:
m += 1
count += 1
return count
def main():
n, m = read_from_stdin()
res = get_answer(n, m)
write_to_stdout(res)
main()
|
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(x) for x in input().split()]
cnt = 0
rst = 0
if n >= m:
rst = n - m
else:
while n != m:
if m < n:
m += 1
elif m % 2 != 0:
m += 1
else:
m /= 2
cnt += 1
rst = cnt
print(rst)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def f(a, b):
while a < b:
a = 2 * a
return a
def g(a, b):
i = 0
while a < b:
a = 2 * a
i += 1
return i
def judge(a, b):
if a >= b:
return a - b
elif b % 2 == 0:
if b == 2 * a:
return 1
elif f(a, b) == b:
return min(judge(a, b // 2) + 1, g(a, b))
else:
return min(judge(a, b // 2) + 1, judge(a, f(a, b)) + f(a, b) - b)
else:
return judge(a, b + 1) + 1
x = input().split()
n = int(x[0])
m = int(x[1])
print(judge(n, m))
|
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
s, t = map(int, input().split())
c = 0
while True:
if t < s:
print(s - t + c)
quit()
else:
if t == s:
print(c)
quit()
if t % 2 == 0:
c += 1
t //= 2
else:
c += 2
t //= 2
t += 1
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
n, m = [int(n) for n in input().split()]
if m == n:
print(0)
exit()
h = []
e = n, 0
h.append(e)
res = 0
while n != m:
if m < n:
m += 1
res += 1
continue
if m % 2 == 0:
m /= 2
res += 1
continue
else:
m += 1
m /= 2
res += 2
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
instr = list(map(int, input().split(" ")))
num = 0
while instr[0] < instr[1]:
if instr[1] % 2:
instr[1] += 1
else:
instr[1] //= 2
num += 1
print(instr[0] - instr[1] + num)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR
|
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 β€ n, m β€ 10^4), separated by a space .
-----Output-----
Print a single number β the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
|
def knopki(n, m):
if n == m:
return "0"
elif n > m:
return n - m
else:
k = 0
while n < m:
if m % 2 == 0:
m //= 2
else:
m += 1
k += 1
k += n - m
return k
x, y = [int(i) for i in input().split()]
print(knopki(x, y))
|
FUNC_DEF IF VAR VAR RETURN STRING IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR 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.