main
[백준-2407번/Java] 조합 본문
https://www.acmicpc.net/problem/2407
* BigInteger로 구현
* 조합 공식
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = in.nextInt();
int M = in.nextInt();
System.out.println(factorial(N).divide(factorial(M)).divide(factorial(N-M)));
}
public static BigInteger factorial(int num) {
if (num == 1)
return new BigInteger("1");
return new BigInteger(String.valueOf(num)).multiply(factorial(num - 1));
}
}
728x90
'Algorithm' 카테고리의 다른 글
[Array-10/Java] 봉우리 (0) | 2022.11.25 |
---|---|
[백준-3036번/Java] 링 (0) | 2022.11.23 |
[백준-1002번/Java] 터렛 (0) | 2022.11.22 |
[백준-3053번/Java] 택시 기하학 (0) | 2022.11.22 |
[백준-2477번/Java] 참외밭 (0) | 2022.11.22 |
Comments