QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667860#9515. 无限地狱masterhuang100 ✓1896ms51316kbC++232.6kb2024-10-23 08:59:522024-10-23 08:59:55

Judging History

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

  • [2024-10-23 08:59:55]
  • 评测
  • 测评结果:100
  • 用时:1896ms
  • 内存:51316kb
  • [2024-10-23 08:59:52]
  • 提交

answer

#include<bits/extc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
using namespace __gnu_pbds;
const int N=2e6+5,mod=998244353,I2=(mod+1)>>1,I32=I2+1;
int U,pw[N],pr[N/13],mu[N],MU[N],tot,sq;bool v[N];LL n;
struct node{int f,g,h;}a[N],b[N];
inline int md(int x){return x>=mod?x-mod:x;}
inline void ad(int &x,int y){x=md(x+y);}
inline int ksm(int x,int p){int s=1;for(;p;(p&1)&&(s=1ll*s*x%mod),x=1ll*x*x%mod,p>>=1);return s;}
inline int TO(LL x){return x<=sq?x:tot+1-(n/x);}
inline void init(int M)
{
	for(int i=2;i<=M;i++)
	{
		if(!v[i]) pr[++pr[0]]=i,mu[i]=-1;
		for(int j=1;j<=pr[0]&&i*pr[j]<=M;j++)
		{
			v[i*pr[j]]=1;if(i%pr[j]==0) break;
			mu[i*pr[j]]=-mu[i];
		}
	}mu[1]=1;
	for(int i=pw[0]=1;i<=M;i++) pw[i]=md(pw[i-1]<<1);a[1].g=1;
	for(int i=2;i<=M;i++)
	{
		a[i].f=md(a[i].f+pw[i/2-1]-1);
		a[i].g=md(a[i].g+mod-(2ll*a[i].f+pw[i-1]-2*mu[i])%mod);
		a[i].h=md(a[i].h+mod-(2ll*a[i].f+pw[i-1]-mu[i])%mod);
		int F=(3ll*(a[i].f+pw[i-2]))%mod;
		for(int j=i;j<=M;j+=i)
			a[j].g=(a[j].g+2ll*(mu[j/i]+mod)*F)%mod,
			a[j].h=(a[j].h+1ll*(mu[j/i]+mod)*F)%mod;
		for(int j=i+i;j<=M;j+=i)
			a[j].f=(a[j].f+a[i].h+1ll*a[i].g*(pw[j/(i<<1)-1]-1))%mod;
	}
	for(int i=1;i<=M;i++) ad(a[i].f,a[i-1].f),ad(a[i].g,a[i-1].g),ad(a[i].h,a[i-1].h);
	for(int i=2;i<=M;i++) mu[i]+=mu[i-1];
	for(int i=1;i<=M;i++) mu[i]=md(mu[i]+mod);
}
int Mu(LL n)
{
	if(n<=U) return mu[n];int w=TO(n);
	if(MU[w]!=-1) return MU[w];int ans=0;
	for(LL i=2,j;i<=n;i=j+1) j=n/(n/i),ans=(ans+(j-i+1)%mod*Mu(n/i))%mod;
	return MU[w]=md(mod+1-ans);
}
int S(LL n)
{
	if(n<=1) return 0;LL k=n>>1;int w=TO(k),r=(k+1)%mod;
	if(n&1) return 2ll*(pw[w]-r+mod)%mod;
	return (1ll*pw[w]*I32+2ll*(mod-r)+1)%mod;
}
node sol(LL n)
{
	if(n<=U) return a[n];int w=TO(n);
	if(b[w].f!=-1) return b[w];int F=0,G=0,H=0;
	for(LL i=2,j;i<=n;i=j+1)
	{
		j=n/(n/i);auto [f,g,h]=sol(n/i);
		F=(F+1ll*g*(S(j)-S(i-1)+mod)+(j-i+1)%mod*h)%mod;
		int x=(3ll*f+1ll*I32*pw[TO(n/i)]-2+mod)%mod*(Mu(j)-Mu(i-1)+mod)%mod;
		G=(G+2ll*x)%mod;H=md(H+x);
	}int x=(2ll*(mod-F)-pw[w]+1+mod)%mod;
	G=md(G+x),H=md(H+x);x=(3ll*F+1ll*I32*pw[w]-2+mod)%mod;
	G=(G+2ll*x)%mod;H=md(H+x);
	return b[w]={F,G,H};
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;
	for(LL i=1,j;i<=n;i=j+1) j=n/(n/i),tot++;
	for(int i=1;i<=tot;i++) MU[i]=-1,b[i]={-1,-1,-1};
	init(U=powl(n/logl(n),2.0/3)*2);sq=sqrtl(n);pw[0]=1;
	for(LL i=1,j,c=tot;i<=n;i=j+1,c--) j=n/(n/i),pw[c]=ksm(2,(n/i)%(mod-1));
	cout<<(sol(n).f+ksm(2,(n-1)%(mod-1)))%mod;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 1ms
memory: 9848kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

score: 4
Accepted
time: 0ms
memory: 11924kb

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

score: 4
Accepted
time: 1ms
memory: 9836kb

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

score: 4
Accepted
time: 1ms
memory: 11880kb

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

score: 4
Accepted
time: 1ms
memory: 11932kb

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: 1ms
memory: 9840kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

score: 13
Accepted
time: 1ms
memory: 9856kb

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 1ms
memory: 11876kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 1ms
memory: 9932kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

score: 13
Accepted
time: 1ms
memory: 11828kb

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: 1ms
memory: 11892kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 1ms
memory: 9836kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 1ms
memory: 11860kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 1ms
memory: 11976kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 1ms
memory: 9984kb

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: 0ms
memory: 11904kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 2ms
memory: 11796kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 0ms
memory: 11880kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 3ms
memory: 9880kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 0ms
memory: 9904kb

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: 46ms
memory: 10456kb

input:

100000000

output:

269652149

result:

ok 1 number(s): "269652149"

Test #22:

score: 22
Accepted
time: 106ms
memory: 17216kb

input:

300000000

output:

421051808

result:

ok 1 number(s): "421051808"

Test #23:

score: 22
Accepted
time: 184ms
memory: 12100kb

input:

700000000

output:

834273337

result:

ok 1 number(s): "834273337"

Test #24:

score: 22
Accepted
time: 236ms
memory: 15248kb

input:

990000000

output:

848544380

result:

ok 1 number(s): "848544380"

Test #25:

score: 22
Accepted
time: 234ms
memory: 15840kb

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: 1323ms
memory: 41488kb

input:

12000000000

output:

877921487

result:

ok 1 number(s): "877921487"

Test #27:

score: 23
Accepted
time: 1679ms
memory: 47212kb

input:

17000000000

output:

691116504

result:

ok 1 number(s): "691116504"

Test #28:

score: 23
Accepted
time: 1878ms
memory: 51288kb

input:

19900000000

output:

87007717

result:

ok 1 number(s): "87007717"

Test #29:

score: 23
Accepted
time: 1894ms
memory: 51316kb

input:

19990000000

output:

455948458

result:

ok 1 number(s): "455948458"

Test #30:

score: 23
Accepted
time: 1896ms
memory: 49624kb

input:

20000000000

output:

128153394

result:

ok 1 number(s): "128153394"