|
| 1 | +import java.io.IOException; |
| 2 | +import java.math.BigInteger; |
| 3 | + |
| 4 | +public class Main { |
| 5 | + private static int N; |
| 6 | + private static int M; |
| 7 | + private static BigInteger answer; |
| 8 | + |
| 9 | + public static void main(String[] args) throws Exception { |
| 10 | + input(); |
| 11 | + |
| 12 | + answer = solution(); |
| 13 | + |
| 14 | + output(); |
| 15 | + } |
| 16 | + |
| 17 | + private static BigInteger solution() { |
| 18 | + BigInteger[] multiplyResult = new BigInteger[101]; |
| 19 | + |
| 20 | + multiplyResult[1] = BigInteger.ONE; |
| 21 | + for (int i = 2; i <= N; i++) { |
| 22 | + multiplyResult[i] = multiplyResult[i-1].multiply(BigInteger.valueOf(i)); |
| 23 | + } |
| 24 | + |
| 25 | + return multiplyResult[N].divide(multiplyResult[N-M]).divide(multiplyResult[M]); |
| 26 | + } |
| 27 | + |
| 28 | + private static void input() throws Exception { |
| 29 | + N = readInt(); |
| 30 | + M = readInt(); |
| 31 | + } |
| 32 | + |
| 33 | + private static void output() { |
| 34 | + System.out.println(answer); |
| 35 | + } |
| 36 | + |
| 37 | + static int readInt() throws IOException { |
| 38 | + int val = 0; |
| 39 | + boolean negative = false; |
| 40 | + |
| 41 | + while (true) { |
| 42 | + int c = System.in.read(); |
| 43 | + if (c == ' ' || c == '\n' || c == -1) { |
| 44 | + break; |
| 45 | + } |
| 46 | + if (c == '-') { |
| 47 | + negative = true; |
| 48 | + continue; |
| 49 | + } |
| 50 | + val = 10 * val + c - 48; |
| 51 | + } |
| 52 | + |
| 53 | + return negative ? -val : val; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * public class Main { |
| 59 | + * |
| 60 | + * public static void main(String[] args) { |
| 61 | + * try { |
| 62 | + * BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1); |
| 63 | + * String[] sp = br.readLine().split(" "); |
| 64 | + * int n = Integer.parseInt(sp[0]); |
| 65 | + * int m = Integer.parseInt(sp[1]); |
| 66 | + * |
| 67 | + * BigInteger res = fact(n).divide(fact(m).multiply(fact(n-m))); |
| 68 | + * System.out.println(res); |
| 69 | + * } catch (IOException e) { |
| 70 | + * e.printStackTrace(); |
| 71 | + * }* } |
| 72 | + * |
| 73 | + * public static BigInteger fact(int n) { |
| 74 | + * BigInteger bi = new BigInteger("1"); |
| 75 | + * for (int i = 1; i <= n; i++) { |
| 76 | + * bi = bi.multiply(BigInteger.valueOf(i)); |
| 77 | + * } |
| 78 | + * return bi;* } |
| 79 | + * } |
| 80 | + * https://www.acmicpc.net/source/6335406 |
| 81 | + */ |
0 commit comments