QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566587 | #9309. Graph | sleep__ | AC ✓ | 488ms | 19476kb | C++20 | 2.9kb | 2024-09-16 00:37:32 | 2024-09-16 00:37:33 |
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(d==3) printf("# %lld %lld\n",nn,mm);
if (mm == 0) {
mm = 1, nn--;
}
ans *= (MInt(nn - 1 + mm).pow(nn - 2) * mm).pow(r-l+1);
}
cout << int(ans) << '\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 5ms
memory: 3908kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 22ms
memory: 4340kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 22ms
memory: 4396kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 36ms
memory: 5100kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 62ms
memory: 6644kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 156ms
memory: 11676kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 320ms
memory: 13532kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 437ms
memory: 18164kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 484ms
memory: 19476kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 471ms
memory: 19460kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 488ms
memory: 19452kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed