QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669108#9515. 无限地狱zhouhuanyi34 29ms3928kbC++141.6kb2024-10-23 17:17:402024-10-23 17:17:50

Judging History

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

  • [2024-10-23 17:17:50]
  • 评测
  • 测评结果:34
  • 用时:29ms
  • 内存:3928kb
  • [2024-10-23 17:17:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 3000
#define mod 998244353
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
	x=x+d>=mod?x+d-mod:x+d;
	return;
}
void Adder2(int &x,int d)
{
	x=x+d<0?x+d+mod:x+d;
	return;
}
int n,pw2[N+1],dp[N+1],DP[N+1],delta[N+1],miu[N+1];
bool nprime[N+1];
int fast_pow(int a,long long b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
int main()
{
	n=read(),pw2[0]=1;
	for (int i=1;i<=n;++i) pw2[i]=2ll*pw2[i-1]%mod;
	for (int i=1;i<=n;++i) miu[i]=1;
	for (int i=2;i<=n;++i)
		if (!nprime[i])
		{
			miu[i]=-1;
			for (int j=(i<<1);j<=n;j+=i)
			{
				miu[j]=-miu[j],nprime[j]=1;
				if ((j/i)%i==0) miu[j]=0;
			}
		}
	for (int i=1;i<=n;++i)
		for (int j=2;j<=i;++j)
		{
			if (miu[j]==-1) Adder(delta[i],MD2(pw2[i/j]-1));
			else if (miu[j]==1) Adder2(delta[i],-MD2(pw2[i/j]-1));
		}
	for (int i=1;i<=n;++i)
	{
		Adder(dp[i],pw2[i-1]),Adder(DP[i],MD2(dp[i]-1));
		for (int j=1;j<=n/i-1;++j)
			for (int k=i*(j+1);k<=min((i+1)*(j+1)-1,n);++k)
			{
				Adder(dp[k],DP[i]);
				Adder(dp[k],1ll*MD2(pw2[(j-1)>>1]-1)*MD2(2ll*MD(dp[i]+DP[i])%mod-1)%mod);
				if (miu[j+1]==1) Adder(DP[k],MD2(3ll*dp[i]%mod-2));
				else if (miu[j+1]==-1) Adder2(DP[k],-MD2(3ll*dp[i]%mod-2));
			}
	}
	printf("%d\n",dp[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: 0ms
memory: 3764kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

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

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

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

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

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

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

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

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

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

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

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

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

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

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

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

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

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: 13ms
memory: 3788kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 20ms
memory: 3928kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 25ms
memory: 3804kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 26ms
memory: 3852kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 29ms
memory: 3804kb

input:

3000

output:

636156660

result:

ok 1 number(s): "636156660"

Subtask #4:

score: 0
Runtime Error

Dependency #3:

100%
Accepted

Test #16:

score: 0
Runtime Error

input:

100000

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%