#include <bits/stdc++.h>
#define N 200030
#define mod 1000000007
using namespace std;
typedef long long ll;
ll n, m, ans, pot[N], fat[N];
ll Pow(ll x, ll p)
{
if(!p) return 1LL;
ll ans = Pow(x, p/2);
ans = (ans*ans)%mod;
if(p & 1) return (ans*x)%mod;
return ans;
}
ll inverse(ll x){
return Pow(x, mod - 2)%mod;
}
ll Choose(ll a, ll b)
{
ll B = (fat[b]*fat[a - b])%mod;
return (fat[a]*inverse(B))%mod;
}
int32_t main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
pot[0] = fat[0] = 1;
m--;
for(int i = 1; i < N; i++) fat[i] = (i*fat[i - 1])%mod;
for(int k = 0; k <= m + 1; k++)
{
ll sign = (k%2 == 0 ? 1 : -1);
ans = (ans + ((sign*Choose(n + 1, k)*Pow(m + 1 - k, n))%mod) )%mod;
}
cout<<(mod + ans)%mod<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1948 KB |
Output is correct |
4 |
Correct |
4 ms |
2004 KB |
Output is correct |
5 |
Correct |
4 ms |
2004 KB |
Output is correct |
6 |
Correct |
4 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2024 KB |
Output is correct |
8 |
Correct |
4 ms |
2028 KB |
Output is correct |
9 |
Correct |
4 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1948 KB |
Output is correct |
4 |
Correct |
4 ms |
2004 KB |
Output is correct |
5 |
Correct |
4 ms |
2004 KB |
Output is correct |
6 |
Correct |
4 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2024 KB |
Output is correct |
8 |
Correct |
4 ms |
2028 KB |
Output is correct |
9 |
Correct |
4 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
2028 KB |
Output is correct |
11 |
Correct |
4 ms |
2028 KB |
Output is correct |
12 |
Correct |
5 ms |
2080 KB |
Output is correct |
13 |
Correct |
4 ms |
2080 KB |
Output is correct |
14 |
Correct |
4 ms |
2132 KB |
Output is correct |
15 |
Correct |
4 ms |
2132 KB |
Output is correct |
16 |
Correct |
4 ms |
2152 KB |
Output is correct |
17 |
Correct |
4 ms |
2152 KB |
Output is correct |
18 |
Correct |
4 ms |
2184 KB |
Output is correct |
19 |
Correct |
4 ms |
2184 KB |
Output is correct |
20 |
Correct |
4 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1948 KB |
Output is correct |
4 |
Correct |
4 ms |
2004 KB |
Output is correct |
5 |
Correct |
4 ms |
2004 KB |
Output is correct |
6 |
Correct |
4 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2024 KB |
Output is correct |
8 |
Correct |
4 ms |
2028 KB |
Output is correct |
9 |
Correct |
4 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
2028 KB |
Output is correct |
11 |
Correct |
4 ms |
2028 KB |
Output is correct |
12 |
Correct |
5 ms |
2080 KB |
Output is correct |
13 |
Correct |
4 ms |
2080 KB |
Output is correct |
14 |
Correct |
4 ms |
2132 KB |
Output is correct |
15 |
Correct |
4 ms |
2132 KB |
Output is correct |
16 |
Correct |
4 ms |
2152 KB |
Output is correct |
17 |
Correct |
4 ms |
2152 KB |
Output is correct |
18 |
Correct |
4 ms |
2184 KB |
Output is correct |
19 |
Correct |
4 ms |
2184 KB |
Output is correct |
20 |
Correct |
4 ms |
2184 KB |
Output is correct |
21 |
Correct |
4 ms |
2184 KB |
Output is correct |
22 |
Correct |
4 ms |
2184 KB |
Output is correct |
23 |
Correct |
4 ms |
2184 KB |
Output is correct |
24 |
Correct |
4 ms |
2184 KB |
Output is correct |
25 |
Correct |
4 ms |
2184 KB |
Output is correct |
26 |
Correct |
4 ms |
2184 KB |
Output is correct |
27 |
Correct |
4 ms |
2184 KB |
Output is correct |
28 |
Correct |
4 ms |
2184 KB |
Output is correct |
29 |
Correct |
4 ms |
2184 KB |
Output is correct |
30 |
Correct |
4 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1948 KB |
Output is correct |
4 |
Correct |
4 ms |
2004 KB |
Output is correct |
5 |
Correct |
4 ms |
2004 KB |
Output is correct |
6 |
Correct |
4 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2024 KB |
Output is correct |
8 |
Correct |
4 ms |
2028 KB |
Output is correct |
9 |
Correct |
4 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
2028 KB |
Output is correct |
11 |
Correct |
4 ms |
2028 KB |
Output is correct |
12 |
Correct |
5 ms |
2080 KB |
Output is correct |
13 |
Correct |
4 ms |
2080 KB |
Output is correct |
14 |
Correct |
4 ms |
2132 KB |
Output is correct |
15 |
Correct |
4 ms |
2132 KB |
Output is correct |
16 |
Correct |
4 ms |
2152 KB |
Output is correct |
17 |
Correct |
4 ms |
2152 KB |
Output is correct |
18 |
Correct |
4 ms |
2184 KB |
Output is correct |
19 |
Correct |
4 ms |
2184 KB |
Output is correct |
20 |
Correct |
4 ms |
2184 KB |
Output is correct |
21 |
Correct |
4 ms |
2184 KB |
Output is correct |
22 |
Correct |
4 ms |
2184 KB |
Output is correct |
23 |
Correct |
4 ms |
2184 KB |
Output is correct |
24 |
Correct |
4 ms |
2184 KB |
Output is correct |
25 |
Correct |
4 ms |
2184 KB |
Output is correct |
26 |
Correct |
4 ms |
2184 KB |
Output is correct |
27 |
Correct |
4 ms |
2184 KB |
Output is correct |
28 |
Correct |
4 ms |
2184 KB |
Output is correct |
29 |
Correct |
4 ms |
2184 KB |
Output is correct |
30 |
Correct |
4 ms |
2184 KB |
Output is correct |
31 |
Correct |
4 ms |
2192 KB |
Output is correct |
32 |
Correct |
4 ms |
2192 KB |
Output is correct |
33 |
Correct |
6 ms |
2192 KB |
Output is correct |
34 |
Correct |
11 ms |
2192 KB |
Output is correct |
35 |
Correct |
44 ms |
2192 KB |
Output is correct |
36 |
Correct |
50 ms |
2228 KB |
Output is correct |
37 |
Correct |
53 ms |
2236 KB |
Output is correct |
38 |
Correct |
10 ms |
2236 KB |
Output is correct |
39 |
Correct |
19 ms |
2236 KB |
Output is correct |
40 |
Correct |
24 ms |
2236 KB |
Output is correct |