Submission #246388

#TimeUsernameProblemLanguageResultExecution timeMemory
246388wwddAsceticism (JOI18_asceticism)C++14
100 / 100
47 ms2808 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MN = 100100; const ll M = 1e9+7; inline ll mul(ll a, ll b) {return (a*b)%M;} ll bp(ll b, ll p) { ll ac = 1; while(p) { if(p&1) {ac = mul(ac,b);} b = mul(b,b); p >>= 1; } return ac; } inline ll inv(ll v) {return bp(v,M-2);} ll fp[MN]; ll fac(ll n) { if(n <= 1) {return 1;} if(fp[n] != -1) {return fp[n];} return fp[n] = mul(fac(n-1),n); } ll ch(ll n, ll k) { if(k < 0 || k > n) {return 0;} if(k <= 0 || k >= n) {return 1;} return mul(mul(fac(n),inv(fac(k))),inv(fac(n-k))); } int main() { memset(fp,-1,sizeof(fp)); ll n,k; cin >> n >> k; ll res = 0; for(int i=0;i<k;i++) { ll sgn = (i&1)?-1:1; res += sgn*mul(bp(k-i,n),ch(n+1,i)); } res = ((res%M)+M)%M; cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...