from collections import deque
def bfs():
q = deque()
q.append(n)
while q:
x = q.popleft()
if x == k:
print(visit[x])
break
for tx in (x - 1, x + 1, x * 2):
if 0 <= tx <= MAX and not visit[tx]:
visit[tx] = visit[x] + 1
q.append(tx)
MAX = 10 ** 5
visit = [0] * (MAX + 1)
n, k = map(int, input().split())
bfs()
'알고리즘' 카테고리의 다른 글
<백준> 2630번 파이썬 알고리즘 [재귀함수] (0) | 2021.10.31 |
---|---|
<백준> 1764번 파이썬 알고리즘 (0) | 2021.10.30 |
<백준> 1676번 자바 알고리즘 (0) | 2021.10.23 |
<백준> 1620번 자바 알고리즘 (0) | 2021.10.12 |
<백준> 11404번 자바 알고리즘 (0) | 2021.10.11 |