QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#565663 | #9309. Graph | ucup-team902 | AC ✓ | 297ms | 23064kb | C++14 | 1.9kb | 2024-09-15 21:58:56 | 2024-09-15 21:58:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int c;
long long g[N];
bool ip[N];
long long ps[N], pc;
void eulerian_sieve(int n) {
fill_n(ip + 1, n, 1);
pc = 0;
ip[1] = 0;
for (int i = 2; i <= n; ++i) {
if (ip[i]) ps[++pc] = i;
for (int j = 1; j <= pc && i * ps[j] <= n; ++j) {
ip[i * ps[j]] = 0;
if (i % ps[j] == 0) break;
}
}
}
long long n, s, w[N];
int id(long long x) { return !x ? 0 : x > s ? n / x
: c - x + 1; }
void cal_g(long long n0) {
n = n0;
s = sqrt(n);
c = 0;
for (long long l = 1, r; l <= n; l = r + 1) {
long long v = n / l;
r = n / v;
w[++c] = v;
g[c] = v - 1;
}
eulerian_sieve(2 * s);
for (int j = 1; j <= pc; ++j) {
long long p = ps[j];
if (1ll * p * p > n) break;
for (int i = 1; 1ll * p * p <= w[i]; ++i) {
g[i] = (g[i] - 1ll * ((g[id(w[i] / p)] - g[id(p - 1)])));
}
}
}
const int mod = 998244353;
long long qpow(long long x, long long y) {
x %= mod;
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
long long cal_purfer(long long x) {
if (x <= 2) return 1;
if (x == 3) return 3;
long long res = g[id(x)] - g[id(x / 2)];
res = (x % mod - res - 1 + mod) % mod * qpow(x % mod, res) % mod;
return res;
}
void solve() {
long long x;
cin >> x;
cal_g(x);
long long ans = 1;
for (long long l = 1, r; l <= x; l = r + 1) {
r = x / (x / l);
long long now = cal_purfer(x / l) % mod;
ans = (__int128)ans % mod * qpow(now, r - l + 1) % mod;
}
printf("%lld\n", (ans + mod) % mod);
}
int main() {
int T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9956kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9888kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 8044kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 2ms
memory: 10160kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 0ms
memory: 9912kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 2ms
memory: 9880kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 2ms
memory: 10024kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 9900kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 2ms
memory: 10160kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 3ms
memory: 9968kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 5ms
memory: 9976kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 12ms
memory: 10512kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 12ms
memory: 10396kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 21ms
memory: 12740kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 42ms
memory: 11020kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 102ms
memory: 17372kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 189ms
memory: 21908kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 265ms
memory: 20980kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 287ms
memory: 21268kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 297ms
memory: 20488kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 289ms
memory: 23064kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed