Advertisement
Araf_12

inverse_mod_process_02

Aug 8th, 2024 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | Source Code | 0 0
  1.  
  2. // second types of template
  3.  
  4.  
  5. ll nCr(ll n, ll r)
  6. {
  7.  
  8.  
  9.    ll p = 1, k = 1;
  10.  
  11.  
  12.    if (n - r < r)
  13.        r = n - r;
  14.  
  15.  
  16.    if (r != 0)
  17.    {
  18.        while (r)
  19.        {
  20.            p *= n;
  21.            k *= r;
  22.  
  23.  
  24.            ll m = __gcd(p, k);
  25.  
  26.  
  27.            p /= m;
  28.            k /= m;
  29.  
  30.  
  31.            n--;
  32.            r--;
  33.        }
  34.    }
  35.  
  36.  
  37.    else
  38.        p = 1;
  39.    return p;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement