Description
给出两个正整数n,m(1<=m<=n<=30) 求出排列组合C(n,m)的个数。
Input
一行两个整数,n,m。请处理到文件尾
Output
每行一个整数,为C(n,m)。
Sample Input
2 1
Sample Output
2
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
ll work(int n ,int k){
if(k > n/2){
k = n-k;
}
ll a = 1;
ll b = 1;
int i;
for(i = 1 ; i <= k ; ++i){
a *= n-i+1;
b *= i;
if(a%b == 0){
a /= b;
b = 1;
}
}
return a/b;
}
int main(){
int n,k;
while(scanf("%d%d",&n,&k)!=EOF){
cout<<work(n,k)<<endl;
}
return 0;
}
f[0]=0;
for(int i=1;i<=400002;i++) f[i]=f[i-1]+log(i*1.0);
double logC(int m,int n){
return f[m]-f[n]-f[m-n];
}
C(m,n)=exp(logC(m,n))