Skip to content

[그리디] 1이 될때까지 질문있습니다. #205

Description

@SUNGMYEONGGI

그리디에서 1이 될때까지 문제 질문입니다.
아래 코드는 제가 작성한 코드입니다. 혹시 책의 예제와는 조금 다른데 예시입력시 같은 출력이 됩니다.
아래 코드도 정답이 될까요??

n, m = map(int, input().split())
cnt = 0

while True:
    if n == 1:
        break
    if n % m == 0:
        n /= m
        cnt += 1
    elif n % m != 0:
        n -= 1
        cnt += 1

print(cnt)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions