Problem Solving/백준
[백준] 2407번: 조합 - [Python/파이썬]
ssun_bear
2023. 4. 25. 22:10
반응형
문제
https://www.acmicpc.net/problem/2407
2407번: 조합
n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)
www.acmicpc.net
nCm을 출력한다.
입력
n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)
출력
nCm을 출력한다.
코드
import math
n, m = map(int, input().split())
up = math.factorial(n)
down = (math.factorial(n - m)) * (math.factorial(m))
print(up // down)
문제 해결
factorial()을 이용하여 해결하였지만, combination()을 이용하여 쉽게 해결 할 수도 있다.
반응형