#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
long long invs[1000003];
long long fact[1000003];
long long ifact[1000003];
long long powmod(long long b, long long n) {
long long ret = 1;
while(n) {
if (n & 1) {
ret *= b;
ret %= mod;
}
b *= b;
b %= mod;
n >>= 1;
}
return ret;
}
int main(){
int n, sigma;
scanf("%d%d",&n,&sigma);
long long ans = 0;
invs[1] = 1;
for (int i = 2; i <= 1000002; i++) invs[i] = invs[mod%i] * (mod - mod / i) % mod;
fact[0] = 1;
for (int i = 1; i <= 1000002; i++) fact[i] = fact[i-1] * i % mod;
ifact[0] = 1;
for (int i = 1; i <= 1000002; i++) ifact[i] = ifact[i-1] * invs[i] % mod;
for (int i = 0; i < sigma; i++) {
long long cursum = fact[n] * ifact[n-i] % mod * ifact[i] % mod * powmod(sigma - i, n) % mod;
if (i % 2) {
ans -= cursum;
} else {
ans += cursum;
}
ans %= mod;
}
ans += mod;
ans %= mod;
printf("%lld\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
24520 KB |
Output is correct |
2 |
Incorrect |
32 ms |
24520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |