QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775034 | #9553. The Hermit | TangWK | WA | 54ms | 15788kb | C++20 | 1.9kb | 2024-11-23 14:33:10 | 2024-11-23 14:33:19 |
Judging History
answer
#include <bits/stdc++.h>
const int mod = 998244353;
void solve() {
int m, n;
std::cin >> m >> n;
auto q_pow = [&] (int x, int p, int mod) {
int ret = 1;
while(p) {
if(p & 1) {
ret = (1ll * ret * x) % mod;
}
x = (1ll * x * x) % mod;
p >>= 1;
}
return ret;
};
std::vector<int> fac(m + 1);
std::vector<int> inv_fac(m + 1);
fac[0] = 1;
for (int i = 1; i <= m; ++i) {
fac[i] = (1ll * fac[i - 1] * i) % mod;
}
inv_fac[m] = q_pow(fac[m], mod - 2, mod);
for (int i = m; i >= 1; --i) {
inv_fac[i - 1] = (1ll * inv_fac[i] * i) % mod;
}
auto C = [&] (int n, int m) {
if(n < m) {
// return 0ll;
return 0ll;
}
int tmp_up = fac[n];
int tmp_down = (1ll * inv_fac[m] * inv_fac[n - m]) % mod;
return (1ll * tmp_up * tmp_down) % mod;
};
std::vector<std::vector<int>> dp(m + 1, std::vector<int>(20));
for (int i = 1; i <= m; ++i) {
dp[i][1] = 1;
for (int j = 1; j * j <= i && j < i; ++j) {
if(i % j == 0) {
int tmp = i / j;
for (int k = 2; k <= 20; ++k) {
if (dp[j][k - 1] > 0) {
dp[i][k] += dp[j][k - 1];
}else {
break;
}
}
if (tmp > j && tmp < i) {
for (int k = 2; k <= 20; ++k) {
if (dp[tmp][k - 1] > 0) {
dp[i][k] += dp[tmp][k - 1];
}else {
break;
}
}
}
}
}
}
int ans = (1ll * n * C(m, n)) % mod;
for (int i = 1; i <= m; ++i) {
int tmp = 0;
for (int k = 1; k <= 20; ++k) {
if (dp[i][k] <= 0) {
break;
}
// printf("{%d, %d} = %d\n", i, k, dp[i][k]);
tmp = (0ll + tmp + 1ll * dp[i][k] * C(m / i - 1, n - k)) % mod;
}
// printf("tmp = %d, ans = %d\n", tmp, ans);
ans = (0ll + mod + ans - tmp) % mod;
}
std::cout << ans << "\n";
return;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// std::cin >> t;
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 53ms
memory: 15700kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4784kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: 0
Accepted
time: 52ms
memory: 15764kb
input:
99998 12345
output:
936396560
result:
ok 1 number(s): "936396560"
Test #6:
score: -100
Wrong Answer
time: 54ms
memory: 15788kb
input:
100000 1
output:
101288180
result:
wrong answer 1st numbers differ - expected: '0', found: '101288180'