#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,abm,bmi2")
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
//#define ld long double
using namespace std;
using ll=long long;
const int inf = 2e18;
const int MN = 2e5+5;
const int mod=1e9+7;
int n,k;
int binpow(int x, int y) {
int res=1;
while(y) {
if(y&1) res=res*x%mod;
x=x*x%mod;
y>>=1;
}
return res;
}
int fact[MN],invfact[MN];
void preprocess() {
fact[0]=invfact[0]=1;
for (int i=1; i<MN; i++) {
fact[i]=fact[i-1]*i%mod;
}
invfact[MN-1]=binpow(fact[MN-1],mod-2);
for (int i=MN-2; i>=1; i--) {
invfact[i]=invfact[i+1]*(i+1)%mod;
}
}
int C(int n, int k) {
return fact[n]*invfact[k]%mod*invfact[n-k]%mod;
}
inline void solve() {
cin>>n>>k;
int ans=0;
for (int i=0; i<=k; i++) {
int cur=C(n+1,i)*binpow(k-i,n)%mod;
if(i&1) ans=(ans+mod-cur)%mod;
else ans=(ans+cur)%mod;
}
cout<<ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
preprocess();
// cin>>t;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
4 ms |
3452 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3452 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
3 ms |
3448 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3460 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
4 ms |
3452 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3452 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
3 ms |
3448 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3460 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3452 KB |
Output is correct |
15 |
Correct |
3 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
3 ms |
3452 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
4 ms |
3452 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3452 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
3 ms |
3448 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3460 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3452 KB |
Output is correct |
15 |
Correct |
3 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
3 ms |
3452 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
3 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
3 ms |
3412 KB |
Output is correct |
25 |
Correct |
3 ms |
3412 KB |
Output is correct |
26 |
Correct |
3 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
3452 KB |
Output is correct |
28 |
Correct |
3 ms |
3412 KB |
Output is correct |
29 |
Correct |
3 ms |
3412 KB |
Output is correct |
30 |
Correct |
3 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
4 ms |
3452 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3452 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
3 ms |
3448 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3460 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3452 KB |
Output is correct |
15 |
Correct |
3 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
3 ms |
3452 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
3 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
3 ms |
3412 KB |
Output is correct |
25 |
Correct |
3 ms |
3412 KB |
Output is correct |
26 |
Correct |
3 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
3452 KB |
Output is correct |
28 |
Correct |
3 ms |
3412 KB |
Output is correct |
29 |
Correct |
3 ms |
3412 KB |
Output is correct |
30 |
Correct |
3 ms |
3448 KB |
Output is correct |
31 |
Correct |
3 ms |
3452 KB |
Output is correct |
32 |
Correct |
3 ms |
3452 KB |
Output is correct |
33 |
Correct |
3 ms |
3412 KB |
Output is correct |
34 |
Correct |
5 ms |
3448 KB |
Output is correct |
35 |
Correct |
9 ms |
3452 KB |
Output is correct |
36 |
Correct |
9 ms |
3452 KB |
Output is correct |
37 |
Correct |
10 ms |
3452 KB |
Output is correct |
38 |
Correct |
4 ms |
3460 KB |
Output is correct |
39 |
Correct |
5 ms |
3412 KB |
Output is correct |
40 |
Correct |
6 ms |
3412 KB |
Output is correct |