QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#604525 | #8761. 另一个计数问题 | UESTC_DECAYALI# | AC ✓ | 477ms | 38804kb | C++20 | 2.4kb | 2024-10-02 11:46:55 | 2024-10-02 11:46:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353, inv2 = (MOD+1)/2, inv3 = (MOD+1)/3, inv6 = (MOD+1)/6;
void inc(int &x, int a){if ((x+=a)>=MOD) x-=MOD;}
void dec(int &x, int a){if ((x-=a)<0) x+=MOD;}
void mul(int &x, int a){x=1LL*x*a%MOD;}
namespace Min25 {
const int $N = 1e6+5;
bool isp[$N]; int pri[$N], totp;
int sp1[$N], g1[$N];
int sp2[$N], g2[$N];
int $n, Sqr, tot, w[$N], ind1[$N], ind2[$N];
void initPri(int n) {
isp[1] = 1;
for (int i=1; i<=n; ++i) {
if (!isp[i]) {
pri[++totp] = i;
sp1[totp] = (sp1[totp-1] + i)%MOD;
sp2[totp] = (sp2[totp-1] + 1LL*i*i)%MOD;
}
for (int j=1; j<=totp&&pri[j]*i<=n; ++j) {
isp[i*pri[j]] = 1;
if (i%pri[j]==0) break;
}
}
}
void initMin25(int n) {
tot = 0;
$n = n;
Sqr = sqrtl(n);
initPri(Sqr);
for (int i=1; i<=n; ) {
int j = n/(n/i);
w[++tot] = n/i;
g1[tot] = w[tot]%MOD;
g2[tot] = g1[tot]*(g1[tot]+1)%MOD*(2*g1[tot]+1)%MOD*inv6%MOD;
g1[tot] = g1[tot]*(g1[tot]+1)%MOD*inv2%MOD;
dec(g2[tot], 1); dec(g1[tot], 1);
if (n/i<=Sqr) ind1[n/i]=tot;
else ind2[n/(n/i)]=tot;
i=j+1;
}
for (int i=1; i<=totp; ++i) {
for (int j=1; j<=tot&&pri[i]*pri[i]<=w[j]; ++j) {
int k = w[j]/pri[i]<=Sqr ? ind1[w[j]/pri[i]] : ind2[n/(w[j]/pri[i])];
dec(g1[j], pri[i]*(g1[k]-sp1[i-1]+MOD)%MOD);
dec(g2[j], pri[i]*pri[i]%MOD*(g2[k]-sp2[i-1]+MOD)%MOD);
}
}
}
}using namespace Min25;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n; int nn=n%MOD;
int sum=(nn+2)*(nn-1+MOD)%MOD*inv2%MOD;
initMin25(n);
int sp=(g1[1]%MOD-g1[2]%MOD+MOD)%MOD,sp2=(g2[1]%MOD-g2[2]%MOD+MOD)%MOD;
// initMin25(n/2);
// sp=(sp-g1[1]%MOD+MOD)%MOD;
// sp2=(sp2-g2[1]%MOD+MOD)%MOD;
int ans=(sum*sum%MOD-(nn*(nn+1)%MOD*(2*nn+1)%MOD*inv6%MOD-1+MOD)%MOD+MOD)%MOD*inv2%MOD;
ans=(ans-sp*sum%MOD+sp2+MOD)%MOD;
ans=(ans+(sp*sp%MOD-sp2+MOD)%MOD*inv2%MOD)%MOD;
cout<<ans<<endl;
// printf("tot=%lld g0=%lld g1=%lld\n", tot, g1[1], g2[1]);
// printf("w:"); for (int i=1; i<=tot; ++i) printf("%lld ", w[i]); puts("");
// printf("g1:"); for (int i=1; i<=tot; ++i) printf("%lld ", g1[i]); puts("");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11756kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13924kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11820kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13792kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 1ms
memory: 11808kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 1ms
memory: 13884kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 1ms
memory: 13816kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 1ms
memory: 11748kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 1ms
memory: 11808kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 1ms
memory: 13852kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 1ms
memory: 13788kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 1ms
memory: 11840kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 0ms
memory: 13964kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 2ms
memory: 13848kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 1ms
memory: 11836kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 1ms
memory: 13768kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 1ms
memory: 11904kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 2ms
memory: 13816kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 1ms
memory: 11812kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 1ms
memory: 11816kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 1ms
memory: 13796kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 13872kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 11908kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 13796kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 13864kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 1ms
memory: 11780kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 1ms
memory: 11844kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 15ms
memory: 12120kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 20ms
memory: 14212kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 16ms
memory: 16244kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 20ms
memory: 14236kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 17ms
memory: 16236kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 20ms
memory: 18188kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 20ms
memory: 14212kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 29ms
memory: 16412kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 43ms
memory: 20604kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 104ms
memory: 17096kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 132ms
memory: 21484kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 205ms
memory: 23500kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 212ms
memory: 25064kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 237ms
memory: 26028kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 248ms
memory: 28048kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 410ms
memory: 34608kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 456ms
memory: 31316kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 471ms
memory: 33400kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 463ms
memory: 34232kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 474ms
memory: 33492kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 463ms
memory: 32028kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 460ms
memory: 34304kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 477ms
memory: 38804kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"