백준 1463번 1로 만들기

highway92·2021년 10월 14일
0

백준

목록 보기
26/27

문제출처 : https://www.acmicpc.net/problem/1463

풀이과정

  1. 입력값에 대하여 문제의 과정을 수행해준다.

  2. 과정 중에 1이 만들어지면 return 한다.

import sys

def solve():
    input = int(sys.stdin.readline())
    table = [[input]]
    cnt = 0

    if input == 1:
        return print(0)

    while True:
        temp = []
        for num in table[cnt]:
            if num-1 == 1:
                    return print(cnt + 1)
            if num % 2 ==0:
                if int(num/2) == 1:
                    return print(cnt + 1)
                temp.append(num//2)

            if num % 3 == 0:
                if int(num/3) == 1:
                    return print(cnt + 1)
                temp.append(num//3)

            temp.append(num-1)
        cnt += 1
        table.append(temp)

solve()
profile
웹 개발자로 활동하고 있습니다.

0개의 댓글