QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688527 | #9515. 无限地狱 | zjy0001 | 55 | 512ms | 144616kb | C++14 | 2.8kb | 2024-10-30 10:28:50 | 2024-10-30 10:28:50 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
#define int LL
using namespace std;
const LL N=2e10+5;
const int M=2e6,K=N/M,Mod=998244353;
LL n;
int vp[M+5],pw2[M+5],mu[M+5];
int smu[M+5],f[M+5],g[M+5],h[M+5],q[M+5],w[M+5];
int nsmu[K+5],nf[K+5],ng[K+5],nh[K+5],nq[K+5],nw[K+5];
inline int qpow(int x,int y,int z=1){
for(;y;(y>>=1)&&(x=(LL)x*x%Mod))if(y&1)z=(LL)z*x%Mod;return z;
}
inline void sieve(int n){
fill(mu+1,mu+n+1,1);
for(int i=2;i<=n;++i)if(!vp[i]){
for(int j=i;j<=n;j+=i)mu[j]*=-1,vp[j]=1;
for(int j=i*i;j<=n;j+=i*i)mu[j]=0;
}
}
inline int Smu(LL n){
if(n<=M)return smu[n];
const int p=::n/n;
if(nsmu[p])return nsmu[p];
const int B=sqrtl(n);
LL z=1;LL l=B,r;
for(int i=B;i>1;--i,l=r)r=n/i,z-=(r-l)*smu[i]+Smu(r);
return z-=n-l,nsmu[p]=z%Mod;
}
inline int Q(LL n){
if(n<=M)return q[n];
const int p=::n/n;
if(nq[p])return nq[p];
int z=qpow(2,(n/2+1)%(Mod-1))-2;
if(n%2==0)z-=qpow(2,(n/2-1)%(Mod-1));
return nq[p]=(z-n+1)%Mod;
}
inline int W(LL n){
if(n<=M)return w[n];
const int p=::n/n;
if(nw[p])return nw[p];
return nw[p]=qpow(2,(n-1)%(Mod-1));
}
inline int F(LL n);
inline int G(LL n);
inline int H(LL n);
inline int F(LL n){
if(n<=M)return f[n];
const int p=::n/n;
if(nf[p])return nf[p];
const int B=sqrtl(n);
int &z=nf[p],i=B;LL l=B,r;
for(z=0;i>1;--i,l=r)
r=n/i,z=(z+1ll*g[i]*(Q(r)-Q(l))+(r-l)%Mod*h[i])%Mod,
z=(z+1ll*G(r)*q[i]+H(r))%Mod;
z=(z+1ll*G(1)*(Q(n)-Q(l))+1ll*H(1)*(n-l))%Mod;
return z;
}
inline int G(LL n){
if(n<=M)return g[n];
const int p=::n/n;
if(ng[p])return ng[p];
return ng[p]=(2ll*(F(n)+H(n))+qpow(2,n%(Mod-1))-1)%Mod;
}
inline int H(LL n){
if(n<=M)return h[n];
const int p=::n/n;
if(nh[p])return nh[p];
const int B=sqrtl(n);
int &z=nh[p],i=B;LL l=B,r;
for(z=(1-2ll*F(n)-qpow(2,n%(Mod-1)))%Mod;i>=1;--i,l=r)
r=n/i,z=(z+(Smu(r)-Smu(l))*(3ll*(f[i]-w[i])-2))%Mod,
z=(z+mu[i]*(3ll*(F(r)-W(r))-2))%Mod;
return z;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n,sieve(M);
pw2[0]=1;
for(int i=1;i<=M;++i)pw2[i]=pw2[i-1]*2%Mod;
for(int i=1;i<=M;++i){
if(i>1)for(int j=1;i*j<=M;++j)if(mu[j])
g[i*j]=(g[i*j]+6ll*mu[j]*(f[i]+pw2[i-2]))%Mod,
h[i*j]=(h[i*j]+3ll*mu[j]*(f[i]+pw2[i-2]))%Mod;
g[i]=(g[i]+(mu[i]-f[i])*2ll-pw2[i-1])%Mod,
h[i]=(h[i]+mu[i]-f[i]*2ll-pw2[i-1])%Mod;
for(int j=2;i*j<=M;++j)f[i*j]=(f[i*j]+h[i]+(pw2[j/2-1]-1ll)*g[i])%Mod;
}
for(int i=1;i<=M;++i)
w[i]=i>1?w[i-1]*2%Mod:1,
q[i]=i>1?(w[i/2]-1+q[i-1])%Mod:0,
f[i]=(f[i]+f[i-1])%Mod,
g[i]=(g[i]+g[i-1])%Mod,
h[i]=(h[i]+h[i-1])%Mod,
smu[i]=smu[i-1]+mu[i];
int ans=(qpow(2,(n-1)%(Mod-1))+F(n))%Mod;
cout<<(ans<0?ans+Mod:ans)<<'\n';
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 460ms
memory: 144224kb
input:
6
output:
38
result:
ok 1 number(s): "38"
Test #2:
score: 4
Accepted
time: 485ms
memory: 144312kb
input:
7
output:
73
result:
ok 1 number(s): "73"
Test #3:
score: 4
Accepted
time: 512ms
memory: 144304kb
input:
8
output:
148
result:
ok 1 number(s): "148"
Test #4:
score: 4
Accepted
time: 491ms
memory: 144312kb
input:
9
output:
284
result:
ok 1 number(s): "284"
Test #5:
score: 4
Accepted
time: 477ms
memory: 144348kb
input:
10
output:
565
result:
ok 1 number(s): "565"
Subtask #2:
score: 13
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 13
Accepted
time: 441ms
memory: 144204kb
input:
30
output:
536938322
result:
ok 1 number(s): "536938322"
Test #7:
score: 13
Accepted
time: 454ms
memory: 144300kb
input:
35
output:
210046687
result:
ok 1 number(s): "210046687"
Test #8:
score: 13
Accepted
time: 448ms
memory: 144616kb
input:
38
output:
680532913
result:
ok 1 number(s): "680532913"
Test #9:
score: 13
Accepted
time: 476ms
memory: 144276kb
input:
39
output:
362030079
result:
ok 1 number(s): "362030079"
Test #10:
score: 13
Accepted
time: 443ms
memory: 144464kb
input:
40
output:
723529503
result:
ok 1 number(s): "723529503"
Subtask #3:
score: 17
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 17
Accepted
time: 506ms
memory: 144284kb
input:
2000
output:
686289840
result:
ok 1 number(s): "686289840"
Test #12:
score: 17
Accepted
time: 462ms
memory: 144608kb
input:
2500
output:
672176744
result:
ok 1 number(s): "672176744"
Test #13:
score: 17
Accepted
time: 444ms
memory: 144272kb
input:
2998
output:
77001108
result:
ok 1 number(s): "77001108"
Test #14:
score: 17
Accepted
time: 439ms
memory: 144284kb
input:
2999
output:
337824775
result:
ok 1 number(s): "337824775"
Test #15:
score: 17
Accepted
time: 473ms
memory: 144272kb
input:
3000
output:
636156660
result:
ok 1 number(s): "636156660"
Subtask #4:
score: 21
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 21
Accepted
time: 448ms
memory: 144256kb
input:
100000
output:
809175948
result:
ok 1 number(s): "809175948"
Test #17:
score: 21
Accepted
time: 454ms
memory: 144460kb
input:
200000
output:
425311829
result:
ok 1 number(s): "425311829"
Test #18:
score: 21
Accepted
time: 454ms
memory: 144284kb
input:
500000
output:
302623178
result:
ok 1 number(s): "302623178"
Test #19:
score: 21
Accepted
time: 510ms
memory: 144252kb
input:
900000
output:
683174559
result:
ok 1 number(s): "683174559"
Test #20:
score: 21
Accepted
time: 475ms
memory: 144312kb
input:
1000000
output:
126560600
result:
ok 1 number(s): "126560600"
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #21:
score: 0
Wrong Answer
time: 449ms
memory: 144496kb
input:
100000000
output:
537873932
result:
wrong answer 1st numbers differ - expected: '269652149', found: '537873932'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%