DasShelmer

Реализация "сочетания" C(m,n) при n >= m

Dec 13th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. // Реализация "сочетания" C(m,n)  n<= 4009
  2. long long unsigned int Combination(const int m, const int n) {
  3.     long long unsigned int fn = 1, dn = 1;
  4.     const int nm = n - m;
  5.     for (int i = 1; i <= n; i++) {
  6.         if (i <= m)
  7.             dn *= i;
  8.         if (i > nm)
  9.             fn *= i;
  10.         if (fn % dn == 0) {
  11.             fn /= dn;
  12.             dn = 1;
  13.         }
  14.     }
  15.     return fn / dn;
  16. }
Add Comment
Please, Sign In to add comment