QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666377 | #8339. Rooted Tree | 1234576 | AC ✓ | 1262ms | 243200kb | C++14 | 2.0kb | 2024-10-22 18:04:27 | 2024-10-22 18:04:27 |
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;
}
详细
Test #1:
score: 100
Accepted
time: 138ms
memory: 85932kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 145ms
memory: 85848kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 208ms
memory: 95860kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 883ms
memory: 190724kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 141ms
memory: 86640kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 953ms
memory: 201548kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 615ms
memory: 151220kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1246ms
memory: 239568kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 344ms
memory: 112764kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 742ms
memory: 173508kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 497ms
memory: 137320kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 458ms
memory: 131112kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 1085ms
memory: 219136kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1252ms
memory: 243200kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1262ms
memory: 242848kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1249ms
memory: 242852kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed