최대 1 분 소요

1️⃣ 문제

문제 링크 : https://www.acmicpc.net/problem/2004


image


2️⃣ 코드

🔥 첫번째 시도 (런타임 에러-RecursionError)

def combination(n,m):
    if n==m or m==0:
        return 1
    return combination(n-1, m-1)+combination(n-1,m)

n,m = map(int, input().split())
num = combination(n,m)
count = 0

while num%10==0:
    count += 1
    num = num//10

print(count)


🔥 두번째 시도

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)))

댓글남기기