#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
ll n,k,fac[N],ans,sum;
ll bpow(ll a,ll b){
ll res = 1;
while(b){
if (b & 1) res = (res*a)%mod;
a = (a*a)%mod; b >>= 1;
}
return res;
}
ll C(ll k,ll n){
ll ts = fac[n],ms = fac[k] * fac[n - k]; ms %= mod;
return (ts * bpow(ms,mod - 2))%mod;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>k; fac[0] = 1;
for (ll i = 1;i < N;i++) fac[i] = (fac[i - 1] * i)%mod; //debug(C(2,4));
for (ll i = 0;i <= k;i++){
sum = (bpow(k - i,n) * C(i, n+1)) % mod; //debug(C(i,n + 1));
if(i&1) ans = (ans - sum + mod) % mod;
else ans = (ans + sum) % mod;
}
debug(ans);
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message
asceticism.cpp: In function 'int main()':
asceticism.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
2 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
2 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1092 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
2 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
2 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1092 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1088 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1092 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
2 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
2 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1092 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1088 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1092 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
2 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
2 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1096 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1100 KB |
Output is correct |
27 |
Correct |
2 ms |
1100 KB |
Output is correct |
28 |
Correct |
1 ms |
1100 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
2 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
2 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1092 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1088 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1092 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
2 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
2 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1096 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1100 KB |
Output is correct |
27 |
Correct |
2 ms |
1100 KB |
Output is correct |
28 |
Correct |
1 ms |
1100 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
2 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
1100 KB |
Output is correct |
32 |
Correct |
2 ms |
1088 KB |
Output is correct |
33 |
Correct |
3 ms |
1100 KB |
Output is correct |
34 |
Correct |
5 ms |
1100 KB |
Output is correct |
35 |
Correct |
20 ms |
1072 KB |
Output is correct |
36 |
Correct |
23 ms |
1100 KB |
Output is correct |
37 |
Correct |
23 ms |
1100 KB |
Output is correct |
38 |
Correct |
4 ms |
964 KB |
Output is correct |
39 |
Correct |
8 ms |
1088 KB |
Output is correct |
40 |
Correct |
10 ms |
1104 KB |
Output is correct |