알고리즘/Baekjoon
[CodingTest] 백준 #11050 이항 계수 1
Happyoon ~
2021. 12. 12. 21:31
728x90
반응형
https://www.acmicpc.net/problem/11050
11050번: 이항 계수 1
첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))
www.acmicpc.net
내 풀이 - 68ms
import math
n,k=map(int,input().split())
res=1
for i in range(n-k+1,n+1):
res*=i
print(int(res/math.factorial(k)))
다른 사람 풀이 - 56ms
N, K = map(int, input().split())
parent = 1
child = 1
for i in range(K):
parent *= (N-i)
child *= (K-i)
print(parent // child)
이 분 코드가 더 빠르다!
반응형