백준
[백준] 11050번: 이항 계수 1 - JAVA
doomole
2024. 2. 7. 15:02
728x90
문제

풀이
이항계수의 풀이는 다음과 같다.
5 2의 이항계수
(5 * 4) / (2 * 1)
7 3의 이항계수
(7 * 6 * 5) / (3 * 2 * 1)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int P = 1;
int Q = 1;
for(int i = 0; i < K; i++) {
P = P * (N - i);
Q = Q * (i + 1);
}
System.out.println(P / Q);
}
}
문의사항이나 피드백은 댓글로 남겨주세요.