求组合数
如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1)
Sample Input
5 //T
3 2 //C3 2
5 3
4 4
3 6
8 0
Sample Output
3
10
1
0
1
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# define LL long long
using namespace std ; double fun(LL n,LL m)//返回类型必须是浮点型,不然会造成误差
{
LL i,j ;
double a=1.0,b=1.0;
double sum = 1.0;
j = m;
while(j--)
{
a=n;
b=m;
sum=sum*a/b; //约分
n--;
m--;
}
return sum;
} int main ()
{
//freopen("in.txt","r",stdin) ;
int T ;
scanf("%d" , &T) ;
while(T--)
{
int n , m ;
cin>>n>>m ;
if (n < m)
{
printf("0\n") ;
continue ;
}
printf("%.0lf\n" , fun(n,m)) ; } return ;
}