백준

백준 11050 - Java

으엉어엉 2024. 9. 9. 20:39
728x90

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BinomialCoefficient {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int k = Integer.parseInt(input[1]);

        if (k == 0 || k == n) {
            System.out.println(1);
            return;
        }

        k = Math.min(k, n - k);

        int result = 1;
        for (int i = 0; i < k; i++) {
            result *= (n - i);
            result /= (i + 1);
        }

        System.out.println(result);
    }
}
728x90

'백준' 카테고리의 다른 글

백준 25192 - Java  (0) 2024.09.11
백준 1037 - Java  (0) 2024.09.11
백준 10872 - Java  (0) 2024.09.09
백준 24723 - Java  (0) 2024.09.09
백준 15439 - Java  (0) 2024.09.09