QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621126 | #9309. Graph | Galex | WA | 15ms | 12232kb | C++14 | 1.5kb | 2024-10-08 09:32:21 | 2024-10-08 09:32:22 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * f;
}
const int MAXN = 1e6 + 5, mod = 998244353;
int qpow(int a, LL b) {
int res = 1;
while (b) {
if (b & 1)
res = 1ll * res * a % mod;
a = 1ll * a * a % mod, b >>= 1;
}
return res;
}
LL n, N;
bool vis[MAXN];
int pr[MAXN], tot = 0;
int m, v[MAXN];
LL g1[MAXN];
int id1[MAXN], id2[MAXN];
void szs() {
for (int i = 2; i <= N; i++) {
if (!vis[i])
pr[++tot] = i;
for (int j = 1; i * pr[j] <= N; j++) {
vis[i * pr[j]] = true;
if (i % pr[j] == 0)
break;
}
}
}
int id(LL x) {
return x <= N ? id1[x] : id2[n / x];
}
int calc(LL m) {
if (m <= 2) return 1;
if (m == 3) return 3;
LL c = g1[id(m)] - g1[id(m / 2)];
return 1ll * qpow(m % mod, c) * ((m - c - 1 + mod) % mod) % mod;
}
signed main() {
n = read(), N = sqrt(n);
szs();
for (int l = 1, r; l <= n; l = r + 1) {
r = n / (n / l), v[++m] = n / l;
g1[m] = n / l - 1;
v[m] <= N ? id1[v[m]] = m : id2[n / v[m]] = m;
}
for (int i = 1; i <= tot; i++)
for (int j = 1; pr[i] * pr[i] <= v[j]; j++)
g1[j] -= g1[id(v[j] / pr[i])] - (i - 1);
int ans = 1;
for (LL l = 1, r; l <= n; l = r + 1)
r = n / (n / l), ans = 1ll * ans * qpow(calc(n / l), r - l + 1) % mod;
printf("%d", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9992kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9996kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 9940kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 9876kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 2ms
memory: 10008kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 9876kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 2ms
memory: 10004kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 10004kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 0ms
memory: 9944kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 0ms
memory: 11988kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 4ms
memory: 10116kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 12ms
memory: 10196kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 12ms
memory: 10252kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 15ms
memory: 12232kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: -100
Wrong Answer
time: 8ms
memory: 12132kb
input:
5120103302
output:
17492326
result:
wrong answer expected '116870489', found '17492326'