# UVa 369
### 題目連結:[UVa369](http://domen111.github.io/UVa-Easy-Viewer/?369)
### 題述:
#### 為了呼應台灣電腦彩券的發行,我們特別推出跟組合有關的題目。以台灣的彩券來說,從46個球中取出6個,共有C(46,6)=9366819種組合。(中特獎的機率:1/936681989,夠低了吧!)給你:5<=N<=100, and 5<=M<=100, and M<=N
#### 我們可以根據下面的公示算出從N個東西中取出M個東西的組合數:

#### 你可以假設你的答案C不會超出 long int 的範圍。
##### 每筆測試資料一行,有2個正整數 N,M。 N=0,M=0代表輸入結束。
### c++ code:
```cpp=
#include <bits/stdc++.h>
using namespace std;
long long fact(int n,int m) {
if ( n - m < m) {
m = n - m ;
}
long double prod = 1 ;
for ( int i = 1 ; i <= m ; i++) {
prod = prod * (n - m + i ) / i ;
}
return prod ;
}
int main () {
//------------------------------------------------
#ifdef local
freopen("UVain.txt","r",stdin);
freopen("UVaout.txt","w",stdout);
#endif
//------------------------------------------------
int n;
int m;
while (cin >> n >> m ) {
if ( n == 0 && m == 0) {
break ;
} else {
cout << n << " things taken " << m << " at a time is "<< fact(n ,m) << " exactly."<< endl ;
}
}
}
```
(不能直接fact(100),會爆)
:::success
**``sample input``**
100 6
20 5
18 6
0 0
:::
:::success
**``sample output``**
100 things taken 6 at a time is 1192052400 exactly.
20 things taken 5 at a time is 15504 exactly.
18 things taken 6 at a time is 18564 exactly.
:::
#### [返回首頁](https://hackmd.io/@fkleofk/APCS#369)
###### tags: `APCS選修` `C++` `UVa`