Submission #47477

#TimeUsernameProblemLanguageResultExecution timeMemory
47477mirbek01Asceticism (JOI18_asceticism)C++17
100 / 100
30 ms2172 KiB
# include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 1e5 + 2; long long binpow(long long a, long long n){ long long res = 1; while(n){ if(n & 1) res = (res * a) % mod; a = (a * a) % mod; n >>= 1; } return res; } long long n, k, f[N], fi[N]; long long cnk(long long n, long long k){ return ((f[n] * fi[n - k]) % mod * fi[k]) % mod; } int main(){ f[0] = 1; fi[0] = binpow(f[0], mod - 2); for(long long i = 1; i < N; i ++){ f[i] = (f[i - 1] * i) % mod; fi[i] = binpow(f[i], mod - 2); } cin >> n >> k; long long ans = 0; for(long long i = 0; i <= k; i ++){ if(i & 1){ ans -= (cnk(n + 1, i) * binpow(k - i, n)) % mod; if(ans < 0) ans += mod; } else { ans += (cnk(n + 1, i) * binpow(k - i, n)) % mod; if(ans > mod) ans -= mod; } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...