编写函数,参数是两个非负整数n和m,返回组合数,其中m≤n≤25。例如,n=25,m=12时答案为5200300。
技巧:化简,避免溢出
typedef long long ll;
ll fun(int m, int n){
if(m < n-m) m = n-m;//this is the key
ll ans = 1;
for(int i = n; i >= m+1; i--)//notice this is m+1 not m
ans *= i;
for(int i = n-m; i > 0; i--)
ans /= i;
return ans;
}