Advertisement
hkshakib

Untitled

Apr 28th, 2020
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll N = 3e5;
  5. const ll mod = 998244353;
  6. ll fac[N], ifac[N], pw[N], inv[N];
  7. ll binpow(ll a, ll b)
  8. {
  9.     a %= mod;
  10.     long long res = 1;
  11.     while (b > 0)
  12.     {
  13.         if (b & 1)
  14.             res = res * a % mod;
  15.         a = a * a % mod;
  16.         b >>= 1;
  17.     }
  18.     return res;
  19. }
  20.  
  21.  
  22. ll ncr(ll n, ll r)
  23. {
  24.     if (r<0 || r>n)
  25.         return 0;
  26.     return 1LL*fac[n]*ifac[r]%mod*ifac[n-r]%mod;
  27. }
  28.  
  29. int main()
  30. {
  31.     fac[0] = ifac[0] = fac[1] = ifac[1] = inv[0] = inv[1] = 1;
  32.     pw[0] = 1, pw[1] = 2;
  33.     for (ll i = 2; i<N; i++)
  34.     {
  35.         fac[i] = 1LL*fac[i-1]*i%mod;
  36.         inv[i] = mod - 1LL*inv[mod%i]*(mod/i)%mod;
  37.         ifac[i] = 1LL*ifac[i-1]*inv[i]%mod;
  38.         pw[i] = 1LL*pw[i-1]*2%mod;
  39.     }
  40.     ll n,k;
  41.     scanf("%lld%lld", &n, &k);
  42.     ll p = n-k;
  43.     ll ans = ncr(n,p)%mod,res=0;
  44.     for(ll i=0; i<=p; i++)
  45.     {
  46.         if(i&1)
  47.             res = (res - ncr(p,i)%mod*binpow(p-i,n)%mod);
  48.         else
  49.             res = (res +  ncr(p,i)%mod*binpow(p-i,n)%mod);
  50.     }
  51.     res%=mod;
  52.     ans=(ans*res)%mod;
  53.     if(p!=n)
  54.         ans=(ans*2)%mod;
  55.     printf("%lld\n",ans);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement