가오리의 코딩일기

[2004] 조합 0의 개수 본문

Python/백준

[2004] 조합 0의 개수

류경혜 2022. 8. 1. 16:00

→ nCr = n!/(n-r)!r!
→ 2의 지수 = n!의 2의 지수 - (n-r)!의 2의 지수 - r!의 2의 지수
→ 5의 지수 = n!의 5의 지수 - (n-r)!의 5의 지수 - r!의 5의 지수
→ 2의 지수와 5의 지수 중 작은 값을 고르면 된다

 

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

def twoCount(n):
    result2 = 0
    while n != 0:
        n = n//2
        result2 += n
    return result2

def fiveCount(n):
    result5 = 0
    while n != 0:
        n = n//5
        result5 += n
    return result5

print(min(twoCount(n)-twoCount(n-m)-twoCount(m),
      fiveCount(n)-fiveCount(n-m)-fiveCount(m)))

 

'Python > 백준' 카테고리의 다른 글

[11728] 배열 합치기  (0) 2022.08.04
[1654] 랜선 자르기  (0) 2022.08.01
[1929] 소수 구하기  (0) 2022.07.21
[6588] 골드바흐의 추측  (0) 2022.07.18
[4948] 베르트랑 공준  (0) 2022.07.17