QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#451246 | #8761. 另一个计数问题 | tarjen# | TL | 1509ms | 52184kb | C++20 | 1.8kb | 2024-06-23 00:09:35 | 2024-06-23 00:09:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const ll Ny2=(mod+1)/2;
const ll Ny6=166374059;
typedef long double lf;
ll Mod(ll x){
long double z=(lf)x/mod;
x-=(ll)z*mod;
return x;
}
const int maxn=1e6+10;
ll pr[maxn],prs[maxn],prs2[maxn],cnt=0,f[maxn];
void add(ll &x,ll y){
if((x+=y)>=mod)x-=mod;
}
void del(ll &x,ll y){
if((x-=y)<0)x+=mod;
}
ll Sum(ll x){
x=Mod(x);
return Mod(Mod(x*(x+1))*Ny2);
}
map<pair<ll,int>,ll> ma,ma2;
ll S(ll x,int m){
while(pr[m]*pr[m]>x)m--;
if(m==0)return Mod(Sum(x)-1+mod);
if(ma.find({x,m})!=ma.end())return ma[{x,m}];
ll res=Mod(Sum(x)-1+mod);
for(int i=1;i<=m;i++){
del(res,Mod(pr[i]*(Mod(S(x/pr[i],i-1)-prs[i-1]+mod))));
}
return ma[{x,m}]=res;
}
ll Sum2(ll x){
x%=mod;
return Mod(Mod(Mod(x*(x+1))*(2*x+1))*Ny6);
}
ll S2(ll x,int m){
while(pr[m]*pr[m]>x)m--;
if(m==0)return Mod(Sum2(x)-1+mod);
if(ma2.find({x,m})!=ma2.end())return ma2[{x,m}];
ll res=Mod(Sum2(x)-1+mod);
for(int i=1;i<=m;i++){
del(res,Mod(Mod(pr[i]*pr[i])*(Mod(S2(x/pr[i],i-1)-prs2[i-1]+mod))));
}
return ma2[{x,m}]=res;
}
signed main()
{
for(ll i=2;i<maxn;i++)if(!f[i]){
cnt++;pr[cnt]=i;
prs[cnt]=Mod(prs[cnt-1]+i);
prs2[cnt]=Mod(prs2[cnt-1]+i*i%mod);
for(int j=i+i;j<maxn;j+=i)f[j]=1;
}
cnt--;
ll n;cin>>n;
ll p1=(S(n,cnt)-S(n/2,cnt)+mod)%mod;
ll p2=(S2(n,cnt)-S2(n/2,cnt)+mod)%mod;
ll z=(Sum(n)-1)*(Sum(n)-1)%mod;
// cout<<"z="<<z<<" p1="<<p1<<" p2="<<p2<<endl;
z=(z-(Sum(n)-1)*p1%mod-(Sum(n)-1-p1)*p1%mod+2*mod)%mod;
// cout<<"z="<<z<<endl;
z=(z+p2)%mod;
z=(z-(Sum2(n)-1)+mod)%mod;
z=z*Ny2%mod;
cout<<z;
// ll ans=0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 14796kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 10ms
memory: 14648kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 10ms
memory: 14732kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 7ms
memory: 14664kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 6ms
memory: 16448kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 11ms
memory: 14668kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 7ms
memory: 16784kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 7ms
memory: 14668kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 10ms
memory: 14792kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 7ms
memory: 14796kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 11ms
memory: 16784kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 3ms
memory: 16404kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 11ms
memory: 14672kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 11ms
memory: 18328kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 7ms
memory: 14816kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 11ms
memory: 14728kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 6ms
memory: 16460kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 11ms
memory: 16848kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 8ms
memory: 14796kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 7ms
memory: 14808kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 7ms
memory: 14960kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 3ms
memory: 16900kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 10ms
memory: 18320kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 9ms
memory: 18560kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 9ms
memory: 15052kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 8ms
memory: 15088kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 11ms
memory: 18480kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 551ms
memory: 35020kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 566ms
memory: 33180kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 569ms
memory: 31484kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 562ms
memory: 35152kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 553ms
memory: 31464kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 565ms
memory: 33516kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 568ms
memory: 31488kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 1065ms
memory: 40396kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 1509ms
memory: 52184kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: -100
Time Limit Exceeded
input:
11640239920