QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604892 | #8761. 另一个计数问题 | UESTC_OldEastWest# | WA | 92ms | 24632kb | C++17 | 1.9kb | 2024-10-02 14:25:58 | 2024-10-02 14:25:59 |
Judging History
answer
#include<cstdio>
#include<cmath>
#define ll long long
#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]+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;
g[i]=(g[i]+mod)%mod;
}
}
}
ll getans(int fl,ll n)
{
cnt=tot=0;
m=sqrt(n);
ready(m);
pre_solve(fl,n);
return g[getnum(n,n)];
}
int main()
{
scanf("%lld",&n);
ll tot=(n+2)%mod*(n-1)%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);
ll totp2=getans(1,n)-getans(1,n>>1);
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*inv2%mod)+totp2)%mod;
printf("%lld",ans);
return 0;
}
/*
7
80
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14324kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 14292kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 1ms
memory: 14256kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 1ms
memory: 14352kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 1ms
memory: 14356kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 0ms
memory: 14236kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 0ms
memory: 14248kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 14288kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 2ms
memory: 14308kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 1ms
memory: 14256kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 1ms
memory: 14320kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 1ms
memory: 14292kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 1ms
memory: 14236kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 1ms
memory: 14256kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 1ms
memory: 14184kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 1ms
memory: 14188kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 1ms
memory: 14284kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 14232kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 16284kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 0ms
memory: 16232kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 1ms
memory: 16304kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 2ms
memory: 18280kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 2ms
memory: 18356kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 18424kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 18424kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 3ms
memory: 20400kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 0ms
memory: 20384kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 57ms
memory: 20548kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 53ms
memory: 20440kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 54ms
memory: 24632kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 53ms
memory: 22468kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 57ms
memory: 22492kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 56ms
memory: 20540kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 58ms
memory: 20480kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: -100
Wrong Answer
time: 92ms
memory: 24564kb
input:
2165916141
output:
591576071
result:
wrong answer 1st numbers differ - expected: '216013547', found: '591576071'