QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575392 | #9309. Graph | propane | AC ✓ | 296ms | 27908kb | C++20 | 2.0kb | 2024-09-19 13:40:16 | 2024-09-19 13:40:16 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<unordered_map>
using namespace std;
using LL = long long;
const int maxn = 1e6 + 5;
bool isPrime[maxn];
int primes[maxn], cnt;
void init(){
isPrime[1] = 1;
for(int i = 2; i < maxn; i++){
if (!isPrime[i]) primes[++cnt] = i;
for(int j = 1; i * primes[j] < maxn; j++){
isPrime[i * primes[j]] = 1;
if (i % primes[j] == 0) break;
}
}
}
const int mod = 998244353;
int mul(int a, int b){
return 1LL * a * b % mod;
}
int qpow(int a, LL b){
int ans = 1;
while(b){
if (b & 1) ans = mul(ans, a);
b >>= 1;
a = mul(a, a);
}
return ans;
}
int id1[maxn], id2[maxn];
LL w[maxn];
LL g[maxn];
LL n;
int get(LL x){
if (x < maxn) return id1[x];
return id2[n / x];
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
init();
cin >> n;
int m = 0;
for(LL l = 1, r; l <= n; l = r + 1){
LL val = n / l;
w[++m] = val;
r = n / val;
if (val < maxn) id1[val] = m;
else id2[n / val] = m;
g[m] = val - 1;
}
for(int i = 1; 1LL * primes[i] * primes[i] <= n; i++){
for(int j = 1; j <= m and 1LL * primes[i] * primes[i] <= w[j]; j++){
g[j] = g[j] - (g[get(w[j] / primes[i])] - (i - 1));
}
}
auto f = [&](LL m){
if (m == 1) return 1;
LL cnt = g[get(m)] - g[get(m / 2)];
LL k = 1;
k += cnt;
if (m - cnt - 1 > 0) k += 1;
int ans = qpow(m % mod, k - 2);
if (m - cnt - 1 > 0) ans = mul(ans, (m - cnt - 1) % mod);
return ans;
};
LL ans = 1;
for(LL l = 1, r; l <= n; l = r + 1){
r = n / (n / l);
ans = mul(ans, qpow(f(n / l), r - l + 1));
}
cout << ans << '\n';
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 8928kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 4ms
memory: 9068kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 4ms
memory: 8992kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 5ms
memory: 12716kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 4ms
memory: 9064kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 5ms
memory: 10976kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 5ms
memory: 12412kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 5ms
memory: 13156kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 5ms
memory: 11052kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 7ms
memory: 13236kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 9ms
memory: 14816kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 15ms
memory: 18160kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 15ms
memory: 13956kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 24ms
memory: 18212kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 42ms
memory: 19636kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 102ms
memory: 23728kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 193ms
memory: 22240kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 260ms
memory: 24224kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 296ms
memory: 27484kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 295ms
memory: 27908kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 291ms
memory: 26404kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed