HDACM2049
错排 + 组合
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int c =sc.nextInt();
while(c-->0){
int n = sc.nextInt();
int m = sc.nextInt();
long sum1 =1;
long a=0,b=1;
long x=1;
long sum2 =n;
for (int i = n-m+1; i < n; i++) {
sum2 *= i;
}
for (int i = 1; i <= m; i++) {
sum1 *= i;
if (i==2) {
x=1;
}
if (i>2) {
x=(i-1)*(a+b);
a=b;
b=x;
}
}
System.out.println(sum2/sum1*x);//记得要先除后成先成的话会超出long的范围
}
}
}