編寫函數,參數是兩個非負整數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;
}