QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667467#9515. 无限地狱masterhuang55 132ms25396kbC++231.8kb2024-10-22 23:19:542024-10-22 23:19:54

Judging History

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

  • [2024-10-22 23:19:54]
  • 评测
  • 测评结果:55
  • 用时:132ms
  • 内存:25396kb
  • [2024-10-22 23:19:54]
  • 提交

answer

#include<bits/stdc++.h>
#define P pair<int,int>
#define fi first
#define se second
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e6+5,mod=998244353,I2=(mod+1)>>1;
int n,f[N],g[N],h[N],pw[N],pr[N],mu[N];bool v[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 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;
}
inline int F(int x)
{
	return (3ll*(f[x]+pw[max(x-2,0)]))%mod;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;
	init(n);int M=n;
	for(int i=pw[0]=1;i<=M;i++) pw[i]=md(pw[i-1]<<1);g[1]=1;
	for(int i=2;i<=M;i++)
	{
		f[i]=md(f[i]+pw[i/2-1]-1);
		g[i]=md(g[i]+mod-(2ll*f[i]+pw[i-1]-2*mu[i])%mod);
		h[i]=md(h[i]+mod-(2ll*f[i]+pw[i-1]-mu[i])%mod);
		for(int j=i;j<=M;j+=i)
			g[j]=(g[j]+2ll*(mu[j/i]+mod)*F(i))%mod,
			h[j]=(h[j]+1ll*(mu[j/i]+mod)*F(i))%mod;
		for(int j=i+i;j<=M;j+=i)
			f[j]=(f[j]+h[i]+1ll*g[i]*(pw[j/(i<<1)-1]-1))%mod;
	}
	for(int i=1;i<=n;i++) ad(f[i],f[i-1]),ad(g[i],g[i-1]),ad(h[i],h[i-1]);
	// for(int i=1;i<=n;i++) cout<<f[i]<<" "<<g[i]<<" "<<h[i]<<"\n";
	// for(int i=1;i<n;i++)
	// {
	// 	int s=0;
	// 	for(int j=1;j<=i;j++)
	// 	{
	// 		s=(s+1ll*(mu[j]+mod)*F(i/j))%mod;
	// 	}
	// 	h[i]=(-2ll*f[i]-ksm(2,i)+1+s)%mod;
	// 	h[i]=(mod+h[i])%mod;
	// 	g[i]=(-2ll*f[i]-ksm(2,i)+1+2ll*s)%mod;
	// 	g[i]=(mod+g[i])%mod;
	// 	for(int j=2;j<=i+1;j++)
	// 	{
	// 		f[i+1]=(f[i+1]+1ll*g[(i+1)/j]*(ksm(2,j/2-1)-1)+h[(i+1)/j])%mod;
	// 	}
	// }
	cout<<(f[n]+ksm(2,n-1))%mod;
	return 0;
}

詳細信息

Subtask #1:

score: 4
Accepted

Test #1:

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

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

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

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

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

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

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

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

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

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

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

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

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

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

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

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

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

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

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

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

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

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

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

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

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

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: 9ms
memory: 10652kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 21ms
memory: 12212kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 55ms
memory: 19964kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 108ms
memory: 24028kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 132ms
memory: 25396kb

input:

1000000

output:

126560600

result:

ok 1 number(s): "126560600"

Subtask #5:

score: 0
Runtime Error

Dependency #4:

100%
Accepted

Test #21:

score: 0
Runtime Error

input:

100000000

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%