# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159780 | combi1k1 | Asceticism (JOI18_asceticism) | C++14 | 14 ms | 1272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int add(int a,int b) {
a += b;
if(a >= mod)a -= mod;
return a;
}
int sub(int a,int b) {
a -= b;
if(a < 0) a += mod;
return a;
}
int mul(int a,int b) {
return 1ll * a * b % mod;
}
int Pow(int a,int b) {
int ans = 1;
for(; b ; b >>= 1, a = mul(a,a)) if (b & 1)
ans = mul(ans, a);
return ans;
}
int Fac[N];
int Inv[N];
int Ckn(int n,int k) {
if (n < k) return 0;
if (k < 0) return 0;
return mul(Fac[n],mul(Inv[k],Inv[n - k]));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int k; cin >> k;
Fac[0] = Inv[0] = 1;
for(int i = 1 ; i < N ; ++i) Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = Pow(Fac[N - 1],mod - 2);
for(int i = N - 2 ; i ; --i) Inv[i] = mul(Inv[i + 1],i + 1);
int ans = 0;
for(int i = 0 ; i < k ; ++i) {
int cur = mul(Ckn(n + 1,i),Pow(k - i,n));
if (i & 1) ans = sub(ans,cur);
else ans = add(ans,cur);
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |