QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606489 | #8761. 另一个计数问题 | Zik_ | AC ✓ | 640ms | 35992kb | C++14 | 2.0kb | 2024-10-03 09:52:18 | 2024-10-03 09:52:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define int long long
using namespace std;
const ld eps=1e-10;
const int N=5e5+3;
const ll mod=998244353;
template<typename T>void read(T &x)
{
x=0;char ch=getchar();ll f=1;
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}x*=f;
}
ll inv(ll i)
{
if(i==1)return 1;
return (mod-mod/i)*inv(mod%i)%mod;
}
int inv6=inv(6);
bool isprime[N];
int p[N+5],pos;
int p1[N+5]={0},p2[N+5]={0};
void prep(){
isprime[0]=isprime[1]=1;
for(int i=2;i<=N;i++)
if(!isprime[i]){
p[++pos]=i;
for(int j=i*2;j<=N;j+=i) isprime[j]=1;
}
for(int i=1;i<=pos;i++){
p1[i]=(p[i]+p1[i-1])%mod;
p2[i]=(p2[i-1]+p[i]*p[i])%mod;
}
}
ll n=0;
int tot=0;
ll R[N*2],g1[N*2],g2[N*2];
int id[N*2];
int where(ll x){
if(x<=N) return id[x];
else return id[N+n/x];
}
void solve() {
prep();
read(n);
for(ll l=1,r;l<=n;l=r+1){
r=n/(n/l);
R[++tot]=r;
if(r<=N) id[r]=tot;
else id[n/r+N]=tot;
}
for(int i=1;i<=tot;i++){
g1[i]=(R[i]%mod*((R[i]+1)%mod*((mod+1)/2)%mod)%mod-1+mod)%mod;
g2[i]=(R[i]%mod*((R[i]+1)%mod)%mod*((2*R[i]+1)%mod)%mod*inv6%mod-1+mod)%mod;
}
for(int i=1;i<=pos&&p[i]*p[i]<=n;i++){
for(int j=tot;R[j]>=p[i]*p[i];j--){
int k=where(R[j]/p[i]);
g1[j]=(g1[j]-(p[i])*(g1[k]-p1[i-1]+mod)%mod+mod)%mod;
g2[j]=(g2[j]-(p[i]*p[i]%mod)*(g2[k]-p2[i-1]+mod)%mod+mod)%mod;
}
}
n%=mod;
int cnt1=(g1[tot]-g1[tot-1]+mod)%mod;
int cnt2=(g2[tot]-g2[tot-1]+mod)%mod;
int ans=(n*(n+1)/2%mod+mod-1-cnt1)%mod;
ans=ans*ans%mod;
ans=(ans-(n*(n+1)%mod*(2*n+1)%mod*inv6%mod)+mod+1+cnt2)%mod*(mod+1)/2%mod;
printf("%lld\n",ans);
}
signed main()
{
int T=1;
//read(T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 13352kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 4ms
memory: 11388kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 2ms
memory: 15176kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11396kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 4ms
memory: 11460kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 4ms
memory: 11472kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 5ms
memory: 13464kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 5ms
memory: 13368kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 11448kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 4ms
memory: 15048kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 4ms
memory: 13284kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 13332kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 0ms
memory: 11468kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 4ms
memory: 11452kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 11356kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 11400kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 11472kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 11524kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 17276kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 0ms
memory: 15448kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 13608kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 15824kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 15764kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 3ms
memory: 15840kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 21332kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 3ms
memory: 17788kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 0ms
memory: 15852kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 27ms
memory: 16532kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 25ms
memory: 21328kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 20ms
memory: 17564kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 21ms
memory: 21288kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 23ms
memory: 21328kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 28ms
memory: 18612kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 24ms
memory: 18664kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 37ms
memory: 17872kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 60ms
memory: 18476kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 128ms
memory: 21052kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 166ms
memory: 23228kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 261ms
memory: 27424kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 258ms
memory: 27200kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 295ms
memory: 27304kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 308ms
memory: 24312kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 522ms
memory: 32512kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 598ms
memory: 33952kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 639ms
memory: 33136kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 624ms
memory: 33412kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 609ms
memory: 35992kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 626ms
memory: 33888kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 639ms
memory: 33584kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 640ms
memory: 35720kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"