less than 1 minute read


문제 유형 : 수학


문제

  • 자연수 N과 정수 K가 주어졌을 때 이항 계수 \textstyle {\binom  nk}를 구하는 프로그램을 작성하시오.

  • https://www.acmicpc.net/problem/11050

제한사항

  • 입력

    첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 0 ≤ K ≤ N)

  • 출력

    \textstyle {\binom  nk} 를 출력한다.


이항계수란?

자연수 n 및 정수 k가 주어졌을 때, 이항 계수\textstyle {\binom  nk}는 다음과 같다.

image]

파이썬에는 팩토리얼 함수를 제공한다. Math라이브러리에서 제공


solution

import math
n,k = map(int,input().split(" "))
#  (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))
# => n! / k!(n-k)!
print(int(math.factorial(n)/(math.factorial(n-k) *math.factorial(k))))
나의 한마디

Tags:

Categories:

Updated: