QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356006 | #8339. Rooted Tree | fxxx# | AC ✓ | 242ms | 394276kb | C++17 | 1.2kb | 2024-03-17 14:39:38 | 2024-03-17 14:39:40 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN 1010
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Rof(i,a,b) for (int i=(a);i>=(b);i--)
using namespace std;
#define maxn 10000007
#define mod 1000000009
#define ll long long
ll a[maxn];
ll mul[maxn];
ll inv[maxn];
ll E[maxn];
ll F[maxn];
ll M, K;
ll qpow(ll base, ll x)
{
ll ans = 1;
while(x) {
if(x & 1) ans = ans * base % mod;
base = base * base % mod, x >>= 1;
}
return ans;
}
int main(){
std::ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> M >> K;
mul[0] = 1;
For(i, 1, K) a[i] = (1 + i * (M - 1)) % mod;
For(i, 1, K) mul[i] = mul[i - 1] * a[i] % mod;
ll iv = qpow(mul[K], mod - 2);
Rof(i, K, 1) {
inv[i] = iv * mul[i - 1] % mod;
iv = iv * a[i] % mod;
}
// For(i, 1, K) cout << a[i] << " " << inv[i] << endl;
For(i, 1, K) {
F[i] = (F[i - 1] + (M - 1) * F[i - 1] % mod * inv[i - 1] % mod + M) % mod;
E[i] = (E[i - 1] + (M) * F[i - 1] % mod * inv[i - 1] % mod + M) % mod;
}
// For(i, 1, K) cout << E[i] << endl;
cout << E[K] << endl;
}
/*
6 2
2 6
83 613210
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 15ms
memory: 27540kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 135ms
memory: 265868kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 183ms
memory: 288996kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 103ms
memory: 163788kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 242ms
memory: 391196kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 43ms
memory: 73980kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 125ms
memory: 215240kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 71ms
memory: 129116kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 67ms
memory: 117664kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 215ms
memory: 340032kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 204ms
memory: 394188kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 228ms
memory: 394212kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 234ms
memory: 394276kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed