QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567566 | #9309. Graph | comeintocalm | WA | 48ms | 85676kb | C++20 | 1.8kb | 2024-09-16 12:48:18 | 2024-09-16 12:48:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 998244353;
LL Fpow(LL b, LL k) {
LL res = 1;
b %= mod;
while(k > 0) {
if(k & 1) res = res * b % mod;
k /= 2;
b = b * b % mod;
}
return res;
}
const int M2 = 1e7;
const int N = 1e7+4;
int prm[N], pcnt = 0, vis1[N], preS[N];
void euler_0() {
for(int i = 2; i <= M2; i++) {
if(!vis1[i]) {
prm[++pcnt] = i;
}
preS[i] = pcnt;
for(int j = 1; j <= pcnt && prm[j] * i <= M2; j++) {
vis1[prm[j] * i] = prm[j];
if(i % prm[j] == 0) break;
}
}
}
int getsqrt(LL n) {
LL t = sqrt(n);
while((t + 1) * (t + 1) <= n) t++;
return t;
}
int getexp(LL n, int p) {
int t = log(n) / log(p);
while(pow(p, t + 1) <= n) t++;
return t;
}
void solve(LL n) {
int bound = getsqrt(n);
LL s_atb = 1, leafed = 0;
for(int i = 1; i <= pcnt && prm[i] <= bound; i++) {
int up_bd = getexp(n, prm[i]);
LL base = prm[i];
if(up_bd >= 3 && pow(prm[i], up_bd) * 2 > n)
leafed++;
for(int j = 1; j <= up_bd; j++, base *= prm[i]) {
LL sF = n / base - n / (base * prm[i]);
LL pF = n / 2 / base - n / 2 / (base * prm[i]);
s_atb = s_atb * Fpow(up_bd - j + 1, (sF - pF) % (mod - 1));
}
}
LL alpha = preS[n] - preS[n / 2] + 1;
LL bans = (n - alpha) % mod * Fpow(2, leafed % (mod - 1)) % mod;
//cout << alpha << " ???" << n << "\n";
LL ans = Fpow(n, (alpha - 1) % (mod - 1)) * bans % mod * s_atb % mod;
cout << ans << "\n";
}
int main() {
euler_0();
LL n;
cin >> n;
if(n == 2) {
printf("1");
return 0;
}
if(n == 3) {
printf("3");
return 0;
}
if(n > 10000000) while(1);
solve(n);
}
详细
Test #1:
score: 100
Accepted
time: 38ms
memory: 85672kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 48ms
memory: 84676kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 43ms
memory: 85676kb
input:
123
output:
-732135154
result:
wrong answer expected '671840470', found '-732135154'