#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 100000;
int const modulo = 1000000007;
int fact[1 + nmax];
void gcd(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
} else {
gcd(b, a % b, x, y);
int aux = x;
x = y;
y = aux - a / b * y;
}
}
void computefact(){
fact[0] = 1;
for(int i = 1; i <= nmax; i++)
fact[i] = 1LL * fact[i - 1] * i % modulo;
}
int invers(int number){
int x, y;
gcd(number, modulo, x, y);
x %= modulo;
if(x < 0)
x += modulo;
return x;
}
int comb(int n, int k){
int result = fact[n];
int result2 = 1LL * fact[k] * fact[n - k] % modulo;
return 1LL * result * invers(result2) % modulo;
}
int lgpow(int a, int b){
if(b == 0)
return 1;
else if(b == 1)
return (modulo + a) % modulo;
else {
int result = lgpow(a, b / 2);
if(b % 2 == 0)
return 1LL * result * result % modulo;
else
return 1LL * result * result % modulo * a % modulo;
}
}
int euler(int n, int m){
int result = 0;
for(int i = 0; i <= m; i++){
result += (1LL * lgpow(-1, i) * comb(n + 1, i) % modulo) * lgpow(m + 1 - i, n) % modulo;
if(modulo <= result)
result -= modulo;
}
return result;
}
int main()
{
computefact();
int n, k;
cin >> n >> k;
cout << euler(n, n - k) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |