QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667844#9515. 无限地狱masterhuang34 6ms11904kbC++232.6kb2024-10-23 08:45:202024-10-23 08:45:26

Judging History

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

  • [2024-10-23 08:45:26]
  • 评测
  • 测评结果:34
  • 用时:6ms
  • 内存:11904kb
  • [2024-10-23 08:45:20]
  • 提交

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=1e6+5,mod=998244353,I2=(mod+1)>>1;
int U,pw[N],pr[N/10],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(int 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;
	if(n&1) return ((pw[TO(k)]-k-1)%mod+mod)*2%mod;
	int t=1ll*pw[TO(k)]*(1+I2)%mod,r=mod-(k+1)%mod;
	return (t+2ll*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*(1+I2)*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*(1+I2)*pw[w]-2+mod)%mod;
	G=(G+2ll*x)%mod;H=md(H+x);
	return a[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));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: 0ms
memory: 9948kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

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

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

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

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

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

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

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

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: 9828kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

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

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 0ms
memory: 9796kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 0ms
memory: 9840kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

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

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: 2ms
memory: 9844kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 0ms
memory: 11904kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 2ms
memory: 9708kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

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

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 0ms
memory: 9780kb

input:

3000

output:

636156660

result:

ok 1 number(s): "636156660"

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #16:

score: 0
Wrong Answer
time: 6ms
memory: 9744kb

input:

100000

output:

986390746

result:

wrong answer 1st numbers differ - expected: '809175948', found: '986390746'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%