topic:
Find the combination of r numbers among n natural numbers (1, 2...n), for example, when n=5, r=3, all combinations are
1 2 31 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
This question only requires the number of combinations
Enter description:
5 3
20 18
Output description:
10
190
#include <iostream> using namespace std; int main(){ int m, i, j, n; int M = 1, N = 1; cin >> m >> n; if(m - n < n){ n = m - n; } for(i = 1; i <= n; i++){ M = M * m; m = m - 1; } for(j = 1; j <= n; j++){ N=N*j; } cout << M / N; }