chyam

[백준] 16953번,python - A->B 본문

백준

[백준] 16953번,python - A->B

chyam_eun 2025. 9. 16. 16:48

https://www.acmicpc.net/problem/16953

a, b = map(int,input().split())
cnt = 1

while a < b:
    if b % 2 == 0: # 짝수면 나눠주기 
        b //= 2 
    else: # 홀수일때
        st = str(b)
        if st[-1] == "1": # 1로 끝나면 1 제외해주기
            st = st[:-1]
        else: # 아니면 만들수없음
            break
        b = int(st)
    cnt += 1

if a == b: 
    print(cnt)
else:
    print(-1)