QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666379 | #8339. Rooted Tree | 1234576 | AC ✓ | 1103ms | 162928kb | C++20 | 2.0kb | 2024-10-22 18:04:48 | 2024-10-22 18:04:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fir first
#define sec second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define lowbit(a) (a & (-a))
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
constexpr int N = 2e7 + 50;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 9;
constexpr int dir[4][2] = {
{-1, 0},
{ 0, 1},
{ 1, 0},
{ 0, -1},
};
mt19937_64 rnd(random_device{}());
uniform_int_distribution<ull> dist(0, ULLONG_MAX); // use dist(rnd)
const int M = 4e7 + 10;
#define int long long
ll qpow(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 f[N], g[N];
ll inv[N];
void solve() {
// int base = 600000038;
// for(int i = 1; i <= 1000; ++i)
// cout << i << ' ' << i * base % mod << '\n';
int m = 1, k = 10000000;
cin >> m >> k;
g[0] = 1;
for(int i = 1; i <= k; ++i)
g[i] = g[i - 1] + m - 1;
// inv[1] = 1;
// for(int i = 2; i <= 10000000; ++i)
// {
// inv[i] = (1ll * inv[mod % i] * (-mod / i) % mod + mod) % mod;
// }
// for(int i = 1; i <= k; ++i)
// {
// if(mod % g[i] >= 10000000)
// {
// cout << "!!!\n";
// return ;
// }
// g[i] = (1ll * inv[mod % g[i]] * (-mod / g[i]) % mod + mod) % mod;
//
// }
ll Ans = 0;
f[0] = 0;
ll pre = 1;
for(int i = 1; i <= k; ++i)
{
f[i] = ((1ll * (m - 1) * f[i - 1] % mod) * pre % mod + f[i - 1] + m) % mod;
pre = qpow(g[i], mod - 2);
if(i < k) Ans = (Ans + f[i] * pre) % mod;
}
Ans += f[k];
Ans %= mod;
cout << Ans << '\n';
}
/*
4 1 3 1
1 2 3 100
9 1 9 1
2 4 5
*/
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7904kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7696kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 66ms
memory: 15828kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 746ms
memory: 114128kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7692kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 796ms
memory: 122264kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 454ms
memory: 71180kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1087ms
memory: 162928kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 200ms
memory: 36360kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 599ms
memory: 91664kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 354ms
memory: 58844kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 326ms
memory: 52756kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 941ms
memory: 141392kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1099ms
memory: 162320kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1103ms
memory: 162796kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1102ms
memory: 162412kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed