QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726156 | #8339. Rooted Tree | ssx | AC ✓ | 201ms | 316140kb | C++20 | 1.2kb | 2024-11-08 22:00:06 | 2024-11-08 22:00:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll, ll>
#define ll long long
const int mod = 1e9 + 9;
const int N = 1e7 + 50;
ll inv[N], a[N], p[N], ip[N];
ll fp(ll a, ll n)
{
ll ans = 1;
a %= mod;
while (n)
{
if (n & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return ans;
}
ll m, k;
void solve()
{
cin >> m >> k;
for (int i = 1; i <= k; i++) a[i] = (i * m - (i - 1)) % mod;
p[0] = 1;
for (int i = 1; i <= k; i++) p[i] = p[i - 1] * a[i] % mod;
ip[k] = fp(p[k], mod - 2);
for (int i = k - 1; i >= 1; i--)
{
ip[i] = ip[i + 1] * a[i + 1] % mod;
}
inv[1] = fp(m, mod - 2);
for (int i = 2; i <= k; i++) inv[i] = ip[i] * p[i - 1] % mod;
ll e = 0, ans = 0, num;
for (int i = 1; i <= k; i++)
{
ans += (e + 1) * m;
ans %= mod;
if (i == 1) num = 1;
else num = ((i - 1) * m - (i - 2)) % mod;
e = ((e * (num - 1)) % mod + (e + 1) * m % mod) * inv[i] % mod;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll T = 1;
//cin >> T;
while (T --)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9788kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9716kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 17ms
memory: 30836kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 150ms
memory: 219096kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9780kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 150ms
memory: 237820kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 94ms
memory: 138428kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 201ms
memory: 315580kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 28ms
memory: 68124kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 111ms
memory: 181372kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 59ms
memory: 109744kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 61ms
memory: 102412kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 167ms
memory: 281040kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 192ms
memory: 316076kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 193ms
memory: 316140kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 194ms
memory: 316088kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed