QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578258 | #9309. Graph | DBsoleil | AC ✓ | 146ms | 15124kb | C++20 | 2.7kb | 2024-09-20 17:48:15 | 2024-09-20 17:48:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
static constexpr int mod = 998244353;
int64_t add(int64_t x, int64_t y) { return (x + y) % mod; }
int64_t sub(int64_t x, int64_t y) { return (x - y + mod) % mod; }
int64_t mul(int64_t x, int64_t y) { return x % mod * (y % mod) % mod; }
int64_t qpow(int64_t x, int64_t y) {
int64_t r = 1; x %= mod;
for (; y; y >>= 1) {
if (y & 1) r = mul(r, x);
x = mul(x, x);
}
return r;
} // qpow
namespace min25 {
vector<bool> np; vector<int> mu;
vector<uint32_t> primes; vector<uint64_t> v;
uint64_t n; uint32_t sqrtn; int pn;
void sieve(int N) {
np.resize(N + 1); mu.resize(N + 1); mu[1] = 1;
for (int i = 2; i <= N; i++) {
if (!np[i]) primes.push_back(i), mu[i] = -1;
for (int p: primes) {
if (i * p > N) break;
mu[i * p] = -mu[i]; np[i * p] = true;
if (i % p == 0) { mu[i * p] = 0; break; }
}
}
}
void init(uint64_t _n) {
n = _n; sqrtn = sqrt(_n);
while ((uint64_t)(sqrtn + 1) * (sqrtn + 1) <= _n) sqrtn++;
sieve(sqrtn); pn = primes.size();
v.reserve(sqrtn * 2 + 10);
for (uint64_t l = 1, r; l <= n; l = r + 1)
r = n / (n / l), v.push_back(n / l);
}
int ind(uint64_t x) { return x <= sqrtn ? v.size() - x : n / x - 1; }
uint64_t fastdiv(uint64_t x, uint64_t _m) { return (uint64_t)((__uint128_t) x * _m >> 64); }
// fp[i] = \sum_{2 <= k <= v[i], k is prime} f(k)
// sf(x) = \sum_{2 <= i <= x} f(i)
// f(x * y) = f(x) * f(y)
template<typename F, typename G>
pair<vector<int64_t>, vector<int64_t>> calcfp(F f, G sf) {
vector<int64_t> pf(pn + 1), fp(v.size());
for (int i = 0; i < pn; i++)
pf[i + 1] = pf[i] + f(primes[i]);
for (int i = 0; i < (int) v.size(); i++) fp[i] = sf(v[i]);
for (int j = 0; j < pn; j++) {
auto pj = primes[j];
auto _pj = ~0ull / pj + 1;
uint64_t z = (uint64_t)pj * pj;
int64_t vv = f(pj);
for (int i = 0; z <= v[i]; i++) {
int k = ind(fastdiv(v[i], _pj));
fp[i] -= vv * (fp[k] - pf[j]);
}
}
return make_pair(move(fp), move(pf));
}
} // min25
int main(void) {
ios_base::sync_with_stdio(false);
int64_t n;
cin >> n;
min25::init(n);
auto f = [](int64_t x) { return 1; };
auto sf = [](int64_t x) { return x - 1; };
auto [fp, pf] = min25::calcfp(f, sf);
auto F = [&](int64_t n)->int64_t {
if (n <= 2) return 1;
if (n == 3) return 3;
int t = fp[min25::ind(n)] - fp[min25::ind(n / 2)];
return mul(qpow(n % mod, t), sub(n % mod, add(t, 1)));
};
int64_t ans = 1;
for (int64_t l = 1, r; l <= n; l = r + 1) {
r = n / (n / l);
ans = mul(ans, qpow(F(n / l), r - l + 1));
}
printf("%lld\n", ans);
return 0;
} // main
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4024kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3872kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 9ms
memory: 4368kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 6ms
memory: 4588kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 14ms
memory: 5292kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 24ms
memory: 6252kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 55ms
memory: 8396kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 100ms
memory: 11888kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 131ms
memory: 14064kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 142ms
memory: 14812kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 142ms
memory: 15000kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 146ms
memory: 15124kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed