Submission #46777

#TimeUsernameProblemLanguageResultExecution timeMemory
46777kyleliuAsceticism (JOI18_asceticism)C++14
100 / 100
30 ms2440 KiB
#include <bits/stdc++.h> // PLEASE using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pp; #define MAXN 100005 #define MAXM 1005 #define MAXP 25 #define A first #define B second #define MP make_pair #define PB push_back const ll INF = 2e9+13; const ll MOD = 1e9+7; int N, K; ll fac[MAXN]; ll ifa[MAXN]; ll mmul(ll a, ll b) { return (a*b)%MOD; } ll madd(ll a, ll b) { return (a+b)%MOD; } ll nck(ll n, ll k) { return mmul(fac[n], mmul(ifa[n-k], ifa[k])); } ll pmod(ll a, ll b) { ll ret = 1LL; while(b) { if(b & 1) ret = mmul(ret, a); a = mmul(a, a); b /= 2LL; } return ret; } ll euler(ll n, ll m) { ll ans = 0; for(int k=0; k<=m+1; k++) { ll add = nck(n+1, k); add = mmul(add, pmod(m+1-k, n)); if(k%2) ans = madd(ans, MOD-add); else ans = madd(ans, add); } return ans; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); fac[0] = 1LL; ifa[0] = 1LL; for(int i=1; i<MAXN; i++) { fac[i] = mmul(fac[i-1], i); ifa[i] = pmod(fac[i], MOD-2); } cin >> N >> K; cout << euler(N, N-K) << 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...