[못 푼 문제] 백준 2004번

장준서·2022년 4월 7일
0

알고리즘 문제

목록 보기
21/29

이번 문제는 단순 조합 계산을 하면 어려워진다. 마지막 끝자리가 0이 나오는 개수를 새보려고 하면 2와 5의 조합을 생각을 해야하는데 사실상 어렵다. 아래 코드를 보면 좀 이해가 될란지 모르겠다.

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


def two_count(n):
    two = 0
    while n != 0:
        n = n // 2
        two += n
    return two

def five_count(n):
    five = 0
    while n != 0:
        n = n // 5
        five += n
    return five

print(min(two_count(n) - two_count(n - m) - two_count(m), five_count(n) - five_count(n - m) - five_count(m)))
profile
let's get ready to rumble

0개의 댓글