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