#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e5+5;
const int M = 1e2+2;
const int mod = 1e9+7;
const ll base = 75;
const int inf = 1e9;
int m, n, t, b[N], d[N], lab[N], q;
int k, a[N], dp[N];
ll ans, tong;
vector<int> adj[N];
vector<pii> vi;
string s[N];
bool vis[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(int &x, int y)
{
x += y;
if(x >= mod)x -= mod;
}
int findp(int u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(int u, int v)
{
u = findp(u);
v = findp(v);
if(u == v)return;
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
int C(int u, int v)
{
if(u > v)return 0;
return 1ll * a[v] * b[u] % mod * b[v-u] % mod;
}
void sol()
{
cin >> n >> k;
a[0] = b[0] = 1;
for(int i = 1; i <= n+1; i ++)
a[i] = 1ll * a[i-1] * i % mod;
b[n+1] = pw(a[n+1], mod-2);
for(int i = n; i > 0; i --)b[i] = 1ll * b[i+1] * (i+1) % mod;
for(int i = 0; i <= k; i ++)
{
tong = 1ll*pw(k-i, n) * C(i, n+1) % mod;
if(i&1)ans = (ans - tong + mod) % mod;
else ans = (ans + tong) % mod;
//cout << i <<" "<<tong<<'\n';
}
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message
asceticism.cpp: In function 'int main()':
asceticism.cpp:81:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
asceticism.cpp:82:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5808 KB |
Output is correct |
2 |
Correct |
3 ms |
5708 KB |
Output is correct |
3 |
Correct |
5 ms |
5708 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
3 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5708 KB |
Output is correct |
7 |
Correct |
3 ms |
5808 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
3 ms |
5708 KB |
Output is correct |
10 |
Correct |
3 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5808 KB |
Output is correct |
2 |
Correct |
3 ms |
5708 KB |
Output is correct |
3 |
Correct |
5 ms |
5708 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
3 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5708 KB |
Output is correct |
7 |
Correct |
3 ms |
5808 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
3 ms |
5708 KB |
Output is correct |
10 |
Correct |
3 ms |
5708 KB |
Output is correct |
11 |
Correct |
3 ms |
5812 KB |
Output is correct |
12 |
Correct |
3 ms |
5708 KB |
Output is correct |
13 |
Correct |
3 ms |
5708 KB |
Output is correct |
14 |
Correct |
3 ms |
5708 KB |
Output is correct |
15 |
Correct |
5 ms |
5708 KB |
Output is correct |
16 |
Correct |
3 ms |
5708 KB |
Output is correct |
17 |
Correct |
3 ms |
5708 KB |
Output is correct |
18 |
Correct |
4 ms |
5708 KB |
Output is correct |
19 |
Correct |
4 ms |
5708 KB |
Output is correct |
20 |
Correct |
3 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5808 KB |
Output is correct |
2 |
Correct |
3 ms |
5708 KB |
Output is correct |
3 |
Correct |
5 ms |
5708 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
3 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5708 KB |
Output is correct |
7 |
Correct |
3 ms |
5808 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
3 ms |
5708 KB |
Output is correct |
10 |
Correct |
3 ms |
5708 KB |
Output is correct |
11 |
Correct |
3 ms |
5812 KB |
Output is correct |
12 |
Correct |
3 ms |
5708 KB |
Output is correct |
13 |
Correct |
3 ms |
5708 KB |
Output is correct |
14 |
Correct |
3 ms |
5708 KB |
Output is correct |
15 |
Correct |
5 ms |
5708 KB |
Output is correct |
16 |
Correct |
3 ms |
5708 KB |
Output is correct |
17 |
Correct |
3 ms |
5708 KB |
Output is correct |
18 |
Correct |
4 ms |
5708 KB |
Output is correct |
19 |
Correct |
4 ms |
5708 KB |
Output is correct |
20 |
Correct |
3 ms |
5708 KB |
Output is correct |
21 |
Correct |
3 ms |
5708 KB |
Output is correct |
22 |
Correct |
3 ms |
5808 KB |
Output is correct |
23 |
Correct |
4 ms |
5816 KB |
Output is correct |
24 |
Correct |
4 ms |
5808 KB |
Output is correct |
25 |
Correct |
3 ms |
5804 KB |
Output is correct |
26 |
Correct |
4 ms |
5808 KB |
Output is correct |
27 |
Correct |
3 ms |
5708 KB |
Output is correct |
28 |
Correct |
4 ms |
5808 KB |
Output is correct |
29 |
Correct |
4 ms |
5708 KB |
Output is correct |
30 |
Correct |
5 ms |
5804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5808 KB |
Output is correct |
2 |
Correct |
3 ms |
5708 KB |
Output is correct |
3 |
Correct |
5 ms |
5708 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
3 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5708 KB |
Output is correct |
7 |
Correct |
3 ms |
5808 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
3 ms |
5708 KB |
Output is correct |
10 |
Correct |
3 ms |
5708 KB |
Output is correct |
11 |
Correct |
3 ms |
5812 KB |
Output is correct |
12 |
Correct |
3 ms |
5708 KB |
Output is correct |
13 |
Correct |
3 ms |
5708 KB |
Output is correct |
14 |
Correct |
3 ms |
5708 KB |
Output is correct |
15 |
Correct |
5 ms |
5708 KB |
Output is correct |
16 |
Correct |
3 ms |
5708 KB |
Output is correct |
17 |
Correct |
3 ms |
5708 KB |
Output is correct |
18 |
Correct |
4 ms |
5708 KB |
Output is correct |
19 |
Correct |
4 ms |
5708 KB |
Output is correct |
20 |
Correct |
3 ms |
5708 KB |
Output is correct |
21 |
Correct |
3 ms |
5708 KB |
Output is correct |
22 |
Correct |
3 ms |
5808 KB |
Output is correct |
23 |
Correct |
4 ms |
5816 KB |
Output is correct |
24 |
Correct |
4 ms |
5808 KB |
Output is correct |
25 |
Correct |
3 ms |
5804 KB |
Output is correct |
26 |
Correct |
4 ms |
5808 KB |
Output is correct |
27 |
Correct |
3 ms |
5708 KB |
Output is correct |
28 |
Correct |
4 ms |
5808 KB |
Output is correct |
29 |
Correct |
4 ms |
5708 KB |
Output is correct |
30 |
Correct |
5 ms |
5804 KB |
Output is correct |
31 |
Correct |
5 ms |
6580 KB |
Output is correct |
32 |
Correct |
6 ms |
6580 KB |
Output is correct |
33 |
Correct |
5 ms |
6476 KB |
Output is correct |
34 |
Correct |
6 ms |
6476 KB |
Output is correct |
35 |
Correct |
12 ms |
6576 KB |
Output is correct |
36 |
Correct |
12 ms |
6476 KB |
Output is correct |
37 |
Correct |
12 ms |
6596 KB |
Output is correct |
38 |
Correct |
5 ms |
5836 KB |
Output is correct |
39 |
Correct |
7 ms |
6384 KB |
Output is correct |
40 |
Correct |
8 ms |
6604 KB |
Output is correct |