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;
typedef long long ll;
typedef long double ld;
#define pb push_back
const int MOD = 1000000007;
int add(int a, int b){
a += b;
if(a >= MOD) a -= MOD;
return a;
}
int mul(int a, int b){
return (1LL*a*b)%MOD;
}
int pw(int a, int b){
if(b == 0) return 1;
int res = pw(a, b/2);
res = mul(res, res);
if(b%2) res = mul(res, a);
return res;
}
int fak[100005];
int inv[100005];
int bin(int n, int k){
if(n < 0 || k < 0 || n < k) return 0;
int res = fak[n];
res = mul(res, inv[k]);
res = mul(res, inv[n-k]);
return res;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
m = n-m;
int res = 0;
fak[0] = inv[0] = 1;
for(int i=1; i<=100000; i++){
fak[i] = mul(fak[i-1], i);
inv[i] = pw(fak[i], MOD-2);
}
for(int k=0; k<=m+1; k++){
int tr = pw(m+1-k, n);
tr = mul(tr, bin(n+1, k));
if(k%2) res = add(res, MOD-tr);
else res = add(res, tr);
}
cout << res << "\n";
return 0;
}
# | 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... |