QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604918 | #8761. 另一个计数问题 | UESTC_OldEastWest# | TL | 1761ms | 41416kb | C++17 | 2.1kb | 2024-10-02 14:34:25 | 2024-10-02 14:34:26 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cmath>
//#define ll long long
#define ll __int128
#define maxn 1000005
using namespace std;
const int M=1000000;
const ll mod=998244353,inv2=499122177,inv6=166374059;
ll n,m;
ll tot,prime[maxn],mark[maxn];
ll cnt,id1[maxn],id2[maxn];//将区间映射到连续的数组
ll g[maxn],v[maxn],sum[2][maxn];
void ready(ll m)
{
for(int i=2;i<=m;++i)
{
if(!mark[i])
{
prime[++tot]=i;
sum[0][tot]=(sum[0][tot-1]+i)%mod;
sum[1][tot]=(sum[1][tot-1]+1LL*i*i%mod)%mod;
}
for(int j=1;j<=tot;++j)
{
ll x=i*prime[j];
if(x>M)
break;
mark[x]=1;
if(i%prime[j]==0)
break;
}
}
}
ll getnum(ll n,ll x)
{
return (x<=m)?id1[x]:id2[n/x];
}
ll f(int fl,ll x)//求f(x)
{
if(x==1)
return 0;
else
return (fl)?x%mod*x%mod:x%mod;
}
ll sumf(int fl,ll x)//求f(2)+...+f(x)的和
{
x%=mod;
ll ret;
if(fl)
{
ret=x%mod*(x+1)%mod*(2*x+1)%mod*inv6%mod;
ret=(ret+mod-1)%mod;
}
else
ret=(x+2)%mod*(x-1)%mod*inv2%mod;
return ret;
}
void pre_solve(int fl,ll n)//预处理g数组
{
for(ll l=1,r;l<=n;l=r+1)
{
r=n/(n/l);
ll val=n/l;
if(val<=m)
id1[val]=++cnt;
else id2[n/val]=++cnt;
v[cnt]=val;
g[cnt]=sumf(fl,val);
}
for(ll j=1;j<=tot;++j)
{
ll x=prime[j];
for(ll i=1;i<=cnt&&x*x<=v[i];++i)
{
g[i]=(g[i]-f(fl,x)*((g[getnum(n,v[i]/x)]-sum[fl][j-1])%mod+mod)%mod)%mod;
g[i]=(g[i]+mod)%mod;
}
}
}
ll getans(int fl,ll n)
{
cnt=tot=0;
m=sqrt((long long)n);
ready(m);
pre_solve(fl,n);
return g[getnum(n,n)];
}
int main()
{
scanf("%lld",&n);
// n=1e11;
ll tot=(n+2)%mod*((n-1)%mod)%mod*inv2%mod;
ll tot2=n%mod*(n+1)%mod*(2*n+1)%mod*inv6%mod;
tot2=(tot2+mod-1)%mod;
ll totp=((getans(0,n)-getans(0,n>>1))%mod+mod)%mod;
ll totp2=((getans(1,n)-getans(1,n>>1))%mod+mod)%mod;
ll ans=((tot*tot%mod-tot2)%mod+mod)%mod;
ans=ans*inv2%mod;
ans=((ans-totp*tot%mod)%mod+mod)%mod;
ans=(ans+(((totp*totp%mod-totp2)%mod+mod)%mod*inv2%mod)+totp2)%mod;
printf("%d",(int)ans);
return 0;
}
/*
7
80
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14472kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 14424kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 14232kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 14420kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 14396kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 0ms
memory: 14428kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 4ms
memory: 14372kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 14448kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 14224kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 14420kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 14232kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 14472kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 2ms
memory: 14472kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 0ms
memory: 14472kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 14404kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 14404kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 14404kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 16464kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 18492kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 4ms
memory: 16236kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 18324kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 20624kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 22652kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 22608kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 24620kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 0ms
memory: 24660kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 3ms
memory: 28760kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 232ms
memory: 30892kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 235ms
memory: 30872kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 236ms
memory: 32944kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 233ms
memory: 30720kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 228ms
memory: 33020kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 237ms
memory: 30872kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 230ms
memory: 28828kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 415ms
memory: 33044kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 587ms
memory: 33060kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 1405ms
memory: 39360kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 1761ms
memory: 41416kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: -100
Time Limit Exceeded
input:
31326230483