#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
const int maxn = 2e5 + 10 , mod = 1e9 + 7 , b = 56 , maxp = 15e5 + 10, inf= 1e9+10 , lg = 20;
int f[maxn] , inv[maxn] ;
int po(int a, int b){
if(b==0)return 1;
int v = po(a,b/2) ;
v= v*v %mod ;
if(b&1) v= v*a % mod ;
return v ;
}
int c(int n , int k){
if(k < 0 || n < k)return 0 ;
return f[n]*inv[k]%mod*inv[n-k]%mod;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
f[0] =1 ;
rep(i , 1 , maxn-1)f[i] =f[i-1] * i % mod ;
inv[maxn-1] = po(f[maxn-1] , mod-2) ;
per(i , maxn-2 , 0){
inv[i] = inv[i+1] * (i+1) % mod ;
}
int n , k ;
cin >> n >> k ;
int ans =0 ;
per(i , k , 1){
int x = po(i , n) * c(n+1 , k-i) %mod;
if((i-k)%2==0){
ans = (ans + x)%mod ;
}else{
ans = (ans - x + mod)%mod ;
}
}
cout << ans << '\n' ;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3420 KB |
Output is correct |
2 |
Correct |
3 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
3 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
3400 KB |
Output is correct |
7 |
Correct |
3 ms |
3420 KB |
Output is correct |
8 |
Correct |
3 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3420 KB |
Output is correct |
2 |
Correct |
3 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
3 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
3400 KB |
Output is correct |
7 |
Correct |
3 ms |
3420 KB |
Output is correct |
8 |
Correct |
3 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
3 ms |
3420 KB |
Output is correct |
13 |
Correct |
3 ms |
3584 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
3 ms |
3416 KB |
Output is correct |
16 |
Correct |
3 ms |
3420 KB |
Output is correct |
17 |
Correct |
3 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
3 ms |
3420 KB |
Output is correct |
20 |
Correct |
3 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3420 KB |
Output is correct |
2 |
Correct |
3 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
3 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
3400 KB |
Output is correct |
7 |
Correct |
3 ms |
3420 KB |
Output is correct |
8 |
Correct |
3 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
3 ms |
3420 KB |
Output is correct |
13 |
Correct |
3 ms |
3584 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
3 ms |
3416 KB |
Output is correct |
16 |
Correct |
3 ms |
3420 KB |
Output is correct |
17 |
Correct |
3 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
3 ms |
3420 KB |
Output is correct |
20 |
Correct |
3 ms |
3420 KB |
Output is correct |
21 |
Correct |
3 ms |
3420 KB |
Output is correct |
22 |
Correct |
3 ms |
3420 KB |
Output is correct |
23 |
Correct |
3 ms |
3420 KB |
Output is correct |
24 |
Correct |
3 ms |
3420 KB |
Output is correct |
25 |
Correct |
3 ms |
3420 KB |
Output is correct |
26 |
Correct |
3 ms |
3592 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
3 ms |
3420 KB |
Output is correct |
29 |
Correct |
3 ms |
3420 KB |
Output is correct |
30 |
Correct |
3 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3420 KB |
Output is correct |
2 |
Correct |
3 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
3 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
3400 KB |
Output is correct |
7 |
Correct |
3 ms |
3420 KB |
Output is correct |
8 |
Correct |
3 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
3 ms |
3420 KB |
Output is correct |
13 |
Correct |
3 ms |
3584 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
3 ms |
3416 KB |
Output is correct |
16 |
Correct |
3 ms |
3420 KB |
Output is correct |
17 |
Correct |
3 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
3 ms |
3420 KB |
Output is correct |
20 |
Correct |
3 ms |
3420 KB |
Output is correct |
21 |
Correct |
3 ms |
3420 KB |
Output is correct |
22 |
Correct |
3 ms |
3420 KB |
Output is correct |
23 |
Correct |
3 ms |
3420 KB |
Output is correct |
24 |
Correct |
3 ms |
3420 KB |
Output is correct |
25 |
Correct |
3 ms |
3420 KB |
Output is correct |
26 |
Correct |
3 ms |
3592 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
3 ms |
3420 KB |
Output is correct |
29 |
Correct |
3 ms |
3420 KB |
Output is correct |
30 |
Correct |
3 ms |
3420 KB |
Output is correct |
31 |
Correct |
3 ms |
3420 KB |
Output is correct |
32 |
Correct |
3 ms |
3420 KB |
Output is correct |
33 |
Correct |
3 ms |
3420 KB |
Output is correct |
34 |
Correct |
4 ms |
3420 KB |
Output is correct |
35 |
Correct |
12 ms |
3584 KB |
Output is correct |
36 |
Correct |
12 ms |
3584 KB |
Output is correct |
37 |
Correct |
14 ms |
3676 KB |
Output is correct |
38 |
Correct |
4 ms |
3420 KB |
Output is correct |
39 |
Correct |
6 ms |
3420 KB |
Output is correct |
40 |
Correct |
7 ms |
3420 KB |
Output is correct |