SHARE
TWEET

Untitled

hkshakib Jun 30th, 2020 949 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int N = 3e5;
  5. const int mod = 998244353;
  6.  
  7. int fac[N], ifac[N], pw[N], inv[N];
  8. int ncr(int n, int r)
  9. {
  10.     if (r<0 || r>n)
  11.         return 0;
  12.     return 1LL*fac[n]*ifac[r]%mod*ifac[n-r]%mod;
  13. }
  14. void precalc()
  15. {
  16.     fac[0] = ifac[0] = fac[1] = ifac[1] = inv[0] = inv[1] = 1;
  17.     for (int i = 2; i<N; i++)
  18.     {
  19.         fac[i] = 1LL*fac[i-1]*i%mod;
  20.         inv[i] = mod - 1LL*inv[mod%i]*(mod/i)%mod;
  21.         ifac[i] = 1LL*ifac[i-1]*inv[i]%mod;
  22.     }
  23. }
  24. int main()
  25. {
  26.     precalc();
  27.     int n,r;
  28.     cin>>n>>r;
  29.     cout<<ncr(n,r)<<endl;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top