Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SUNGMYEONGGI opened this issue Jul 12, 2023 · 0 comments
Open

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

SUNGMYEONGGI opened this issue Jul 12, 2023 · 0 comments

Comments

@SUNGMYEONGGI
Copy link

그리디에서 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant