飞花的糖果
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
N个的两两不相同糖果,他想要拿出例如,飞花壕有3块送给他心仪的程序媛,他有四种选择,分别是①、②、③, ①、②、④, ①、③、④, ②、③、④ 这四种选择。
多组输入。对于每组输入,有两个整数M(M <= 10),分表代表有M个送给他心仪的程序媛。
输出为一个整数,代表飞花壕可以做出的选择的方案数。
Example Input
4 3 5 2
Example Output
4 10
Hint
Author
GLSilence
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(fun(n, m));
}
sc.close();
}
public static int fun(int n, int m) {
int s1 = 1;
int s2 = 1;
for (int i = n; i > n - m; i--) {
s1 = s1 * i;
}
for (int i = 2; i <= m; i++) {
s2 = s2 * i;
}
int result = s1 / s2;
return result;
}
}