Alex_tz307

Combinari

Sep 28th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. int invers(int x) {
  2.     int exp = mod - 2, ans = 1;
  3.     while(exp) {
  4.         if(exp & 1)
  5.             ans = (ans * x) % mod;
  6.         x = (x * x) % mod;
  7.         exp >>= 1;
  8.     }
  9.     return ans;
  10. }
  11.  
  12. int comb(int n, int k, vector < int >& fact) {
  13.     int ans = fact[n];
  14.     ans = (ans * invers(fact[k])) % mod;
  15.     ans = (ans * invers(fact[n - k])) % mod;
  16.     return ans;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment