QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566537 | #9309. Graph | sleep__ | WA | 1ms | 3700kb | C++20 | 2.8kb | 2024-09-16 00:25:26 | 2024-09-16 00:25:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <int P>
int mod(int v) {
return (v < 0) ? (v + P) : (v < P ? v : (v - P));
}
template <int P>
struct ModInt {
int v;
ModInt(int val = 0) : v(mod<P>(val)) {}
ModInt(ll val) : v(mod<P>(val % P)) {}
ModInt& operator+=(const ModInt& b) {
if ((v += b.v) >= P) {
v -= P;
}
return *this;
}
ModInt& operator-=(const ModInt& b) {
if ((v -= b.v) < 0) {
v += P;
}
return *this;
}
ModInt& operator*=(const ModInt& b) {
v = 1ll * v * b.v % P;
return *this;
}
friend ModInt operator+(ModInt a, const ModInt& b) { return a += b; }
friend ModInt operator-(ModInt a, const ModInt& b) { return a -= b; }
friend ModInt operator*(ModInt a, const ModInt& b) { return a *= b; }
ModInt pow(ll b) const {
if (b < 0) {
(b %= P - 1) += P - 1;
}
ModInt c = 1, a = *this;
for (; b; b >>= 1, a *= a) {
if (b & 1) {
c *= a;
}
}
return c;
}
explicit operator int() const { return v; }
};
using MInt = ModInt<998244353>;
struct Arr {
const ll N, S;
vector<ll> vl, vr;
Arr(ll n) : N(n), S(sqrtl(n)), vl(S + 1), vr(S + 1) {}
ll& operator[](ll i) {
return i <= S ? vl[i] : vr[N / i];
}
const ll& operator[](ll i) const {
return i <= S ? vl[i] : vr[N / i];
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
ll n;
cin >> n;
ll s = sqrtl(n);
vector<int> vis(s + 1), pri;
for (int i = 2; i <= s; i++) {
if (!vis[i]) {
pri.emplace_back(i);
}
for (auto p : pri) {
if (1ll * i * p > s) {
break;
}
vis[i * p] = true;
if (i % p == 0) {
break;
}
}
}
vector<ll> val;
Arr f(n);
for (ll i = 1; i <= n; i++) {
val.emplace_back(n / i);
f[val.back()] = val.back() - 1;
i = n / (n / i);
}
for (int i = 0; i < (int)pri.size(); i++) {
for (auto v : val) {
if (1ll * pri[i] * pri[i] > v) {
break;
}
f[v] -= f[v / pri[i]] - i;
}
}
// cout << int(f[n]) << '\n';
MInt ans = 1;
for (ll l = 1, r; l <= n; l = r + 1) {
ll d = n / l;
r = n / d;
if (d <= 2) {
continue;
}
auto nn = f[d] - f[d / 2] + 2;
auto mm = d - nn + 1;
if (mm == 0) {
mm = 1, nn--;
}
ans *= (r - l + 1) * MInt(nn - 1 + mm).pow(nn - 2) * mm;
}
cout << int(ans) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3700kb
input:
123
output:
933844287
result:
wrong answer expected '671840470', found '933844287'