practivceAlgorithm/백준
[백준][Python] 16953 A -> B
findTheValue
2021. 12. 7. 22:55
그리디하게 맨 뒷 자리가 짝수면 2로 나누고 1이면 1빼면 된다.
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
cnt = 1
while A != B:
if A > B or (B % 10 != 1 and B % 2 != 0):
cnt = -1
break
if B & 1:
B //= 10
cnt += 1
else:
B //= 2
cnt += 1
print(cnt)