yuns

1이 될 때까지 본문

algorithms/#3 Greedy algorithm

1이 될 때까지

yuuuun 2020. 11. 4. 15:03
반응형
n, k = map(int, input().split())
cnt = 0
res = 0
# n 이 k보다 큰 경우
while n >= k:
    #n이 k로 나누어 떨어지지 않을 경우 n -= 1
    while n % k != 0:
        n -= 1
        res += 1
    n /= k
    res += 1

res += (n-1)
print(res)
반응형

'algorithms > #3 Greedy algorithm' 카테고리의 다른 글

숫자 카드 게임  (0) 2020.11.04
큰 수의 법칙  (0) 2020.11.04
Comments