출처 | 이항계수 1 [백준 11050]
자연수 N(N)과 정수 K(K)가 주어졌을 때 이항 계수 (NK)(\binom{N}{K})를 구하는 프로그램을 작성하시오.
첫째 줄에 N(N)과 K(K)가 주어진다. (1 ≤ N(N) ≤ 10, 0 ≤ K(K) ≤ N(N))
(NK)(\binom{N}{K})를 출력한다.
from sys import stdin
N, R = map(int, stdin.readline().split())
result = 1
if (R < N/2+1):
for i in range(1, R + 1):
result *= N
result //= i
N -= 1
else:
R = N - R
for i in range(1, R + 1):
result *= N
result //= i
N -= 1
print(result)