QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777385 | #9553. The Hermit | baitang | WA | 32ms | 27452kb | C++20 | 3.1kb | 2024-11-24 01:52:11 | 2024-11-24 01:52:12 |
Judging History
answer
#include<bits/stdc++.h>
using pii = std::pair<int, int>;
using i64 = long long;
static constexpr int mod = 998244353;
class combMath
{
public:
static constexpr int size = 2e5;
i64 fact[size + 1];
i64 finv[size + 1];
i64 inve[size + 1];
static constexpr int mod = 998244353;
void factor()
{
fact[0] = 1; fact[1] = 1;
inv();
finv[0] = 1;
finv[1] = inve[1];
for (int i = 2; i <= size; ++i) fact[i] = fact[i - 1] * i % mod, finv[i] = finv[i - 1] * inve[i] % mod;
}
void inv()
{
inve[1] = 1;
for (int i = 2; i <= size; ++i)
{
inve[i] = (mod - mod / i) * inve[mod % i] % mod;
}
}
public:
combMath() { factor(); }
i64 power(i64 x, i64 p)
{
i64 temp = p, ans = 1;
while (temp)
{
if (temp & 1) ans = ans * x % mod;
temp >>= 1;
x = x * x % mod;
}
return ans;
}
i64 getInv(i64 x)
{
return power(x, mod - 2);
}
i64 inv(i64 x)
{
return inve[x];
}
i64 facInv(i64 x)
{
return finv[x];
}
i64 getFac(i64 obj)
{
return fact[obj];
}
i64 perm(i64 n, i64 m, bool mode)
{
if (mode) return fact[n] * finv[n - m] % mod;
else return fact[n] / fact[n - m];
}
i64 comb(i64 n, i64 m, bool mode = 1)
{
if (mode) return fact[n] * finv[n - m] % mod * finv[m] % mod;
else return fact[n] / fact[n - m] / fact[m];
}
i64 stirling(i64 n, i64 m) // 'n' balls into 'm' boxes, boxes DO NOT differ while balls differ.
{
i64 ans = 0;
for (int i = 0; i < m; ++i)
ans = (ans + (i & 1 ? -1 : 1) * comb(m, i, 1) * power(m - i, n) % mod) % mod;
ans = ans * finv[m] % mod;
return (ans + mod) % mod;
}
i64 catalan(int n, int mode) // n different nums pop in a stack in an certain order, how many ramifications there will be.
{
std::vector<i64> dp(n + 1, 1);
if (mode) for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] * (4LL * i % mod - 2) % mod * inv(i + 1) % mod;
else for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] * (4 * i - 2) / (i + 1);
return dp[n];
}
} cm;
using namespace std;
void solve()
{
int m, n;
cin >> m >> n;
long long ans = (cm.comb(m, n, 1) * n) % mod;
vector<vector<long long>>f(m + 1, vector<long long>(20, 0));
for (int i = 1; i <= m/2; i++)
{
f[i][0] = 1;
for (int j = (i << 1); j <= m; j += i)
{
for (int k = 0; f[i][k]; k++)
{
f[j][k + 1] = (f[j][k + 1] + f[i][k]) % mod;
}
}
}
for (int i = 1; i <= m; i++)
{
int cnt = m / i - 1;
int minn=min(19,n-1);
for (int j = max(n-cnt-1,0); j<=minn; j++)
ans = (ans - f[i][j] * cm.comb(cnt, n - j - 1, 1) % mod) % mod;
}
cout << (ans+mod)%mod << '\n';
}
int main()
{
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8508kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8288kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 30ms
memory: 27420kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 5ms
memory: 10256kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: 0
Accepted
time: 32ms
memory: 27452kb
input:
99998 12345
output:
936396560
result:
ok 1 number(s): "936396560"
Test #6:
score: -100
Wrong Answer
time: 29ms
memory: 27404kb
input:
100000 1
output:
50000
result:
wrong answer 1st numbers differ - expected: '0', found: '50000'