Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll N = 3e5;
- const ll mod = 998244353;
- ll fac[N], ifac[N], pw[N], inv[N];
- ll binpow(ll a, ll b)
- {
- a %= mod;
- long long res = 1;
- while (b > 0)
- {
- if (b & 1)
- res = res * a % mod;
- a = a * a % mod;
- b >>= 1;
- }
- return res;
- }
- ll ncr(ll n, ll r)
- {
- if (r<0 || r>n)
- return 0;
- return 1LL*fac[n]*ifac[r]%mod*ifac[n-r]%mod;
- }
- int main()
- {
- fac[0] = ifac[0] = fac[1] = ifac[1] = inv[0] = inv[1] = 1;
- pw[0] = 1, pw[1] = 2;
- for (ll i = 2; i<N; i++)
- {
- fac[i] = 1LL*fac[i-1]*i%mod;
- inv[i] = mod - 1LL*inv[mod%i]*(mod/i)%mod;
- ifac[i] = 1LL*ifac[i-1]*inv[i]%mod;
- pw[i] = 1LL*pw[i-1]*2%mod;
- }
- ll n,k;
- scanf("%lld%lld", &n, &k);
- ll p = n-k;
- ll ans = ncr(n,p)%mod,res=0;
- for(ll i=0; i<=p; i++)
- {
- if(i&1)
- res = (res - ncr(p,i)%mod*binpow(p-i,n)%mod);
- else
- res = (res + ncr(p,i)%mod*binpow(p-i,n)%mod);
- }
- res%=mod;
- ans=(ans*res)%mod;
- if(p!=n)
- ans=(ans*2)%mod;
- printf("%lld\n",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement