QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688532#9515. 无限地狱zjy0001100 ✓1537ms144820kbC++142.8kb2024-10-30 10:34:392024-10-30 10:34:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 10:34:39]
  • 评测
  • 测评结果:100
  • 用时:1537ms
  • 内存:144820kb
  • [2024-10-30 10:34:39]
  • 提交

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)*(w[i/2]-1)+H(r))%Mod;
	z=(z+Q(n)-Q(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: 767ms
memory: 144648kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

score: 4
Accepted
time: 743ms
memory: 144212kb

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

score: 4
Accepted
time: 776ms
memory: 144680kb

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

score: 4
Accepted
time: 750ms
memory: 144284kb

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

score: 4
Accepted
time: 769ms
memory: 144152kb

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: 762ms
memory: 144560kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

score: 13
Accepted
time: 781ms
memory: 144216kb

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 778ms
memory: 144292kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 751ms
memory: 144284kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

score: 13
Accepted
time: 775ms
memory: 144280kb

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: 750ms
memory: 144352kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 766ms
memory: 144216kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 759ms
memory: 144216kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 788ms
memory: 144276kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 766ms
memory: 144300kb

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: 788ms
memory: 144152kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 722ms
memory: 144276kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 800ms
memory: 144684kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 766ms
memory: 144276kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 732ms
memory: 144276kb

input:

1000000

output:

126560600

result:

ok 1 number(s): "126560600"

Subtask #5:

score: 22
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 22
Accepted
time: 751ms
memory: 144308kb

input:

100000000

output:

269652149

result:

ok 1 number(s): "269652149"

Test #22:

score: 22
Accepted
time: 776ms
memory: 144820kb

input:

300000000

output:

421051808

result:

ok 1 number(s): "421051808"

Test #23:

score: 22
Accepted
time: 767ms
memory: 144340kb

input:

700000000

output:

834273337

result:

ok 1 number(s): "834273337"

Test #24:

score: 22
Accepted
time: 776ms
memory: 144324kb

input:

990000000

output:

848544380

result:

ok 1 number(s): "848544380"

Test #25:

score: 22
Accepted
time: 816ms
memory: 144448kb

input:

1000000000

output:

341773916

result:

ok 1 number(s): "341773916"

Subtask #6:

score: 23
Accepted

Dependency #5:

100%
Accepted

Test #26:

score: 23
Accepted
time: 1209ms
memory: 144640kb

input:

12000000000

output:

877921487

result:

ok 1 number(s): "877921487"

Test #27:

score: 23
Accepted
time: 1438ms
memory: 144680kb

input:

17000000000

output:

691116504

result:

ok 1 number(s): "691116504"

Test #28:

score: 23
Accepted
time: 1513ms
memory: 144712kb

input:

19900000000

output:

87007717

result:

ok 1 number(s): "87007717"

Test #29:

score: 23
Accepted
time: 1537ms
memory: 144688kb

input:

19990000000

output:

455948458

result:

ok 1 number(s): "455948458"

Test #30:

score: 23
Accepted
time: 1489ms
memory: 144680kb

input:

20000000000

output:

128153394

result:

ok 1 number(s): "128153394"