hdu 2519 求组合数
求组合数
如果求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
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # define LL long long 7 using namespace std ; 8 9 double fun(LL n,LL m)//返回类型必须是浮点型,不然会造成误差 10 { 11 LL i,j ; 12 double a=1.0,b=1.0; 13 double sum = 1.0; 14 j = m; 15 while(j--) 16 { 17 a=n; 18 b=m; 19 sum=sum*a/b; //约分 20 n--; 21 m--; 22 } 23 return sum; 24 } 25 26 int main () 27 { 28 //freopen("in.txt","r",stdin) ; 29 int T ; 30 scanf("%d" , &T) ; 31 while(T--) 32 { 33 int n , m ; 34 cin>>n>>m ; 35 if (n < m) 36 { 37 printf("0\n") ; 38 continue ; 39 } 40 printf("%.0lf\n" , fun(n,m)) ; 41 42 43 } 44 45 return 0 ; 46 }