QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245976#5495. 寿司晚宴cjs100 ✓834ms52752kbC++141.7kb2023-11-10 14:55:572023-11-10 14:55:59

Judging History

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

  • [2023-11-10 14:55:59]
  • 评测
  • 测评结果:100
  • 用时:834ms
  • 内存:52752kb
  • [2023-11-10 14:55:57]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=505,M=105,K=260;
int n,m,cnt,P;
int p[M],q[M],a[M],val[M],v[N];
int st[N],f[N][K],h[N][K];
int g[M][K][K];
bool vis[N];
bool check(int x){
	for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
	return 1;
}
signed main()
{
	cin>>n>>P;
	for(int i=2;i<=n;i++){
		if(check(i)){
			if(i*i<=n){
				p[++cnt]=i;
			}
			else {
				q[++m]=i;
			}
		}
	}
	q[0]=1;
	for(int s=0;s<1<<cnt;s++){
		int t=0,tot=0;
		for(int i=0;i<cnt;i++){
			if(s>>i&1){
				a[++t]=p[i+1];
				val[t]=1<<i;
			}
		}
		memset(vis,0,sizeof(vis));
		memset(st,0,sizeof(st));
		vis[1]=1;
		for(int i=1;i<=t;i++){
			for(int j=a[i];j<=n;j++)if(j%a[i]==0){
				vis[j]|=vis[j/a[i]];
			}
		}
		for(int i=1;i<=n;i++)if(vis[i]){
			v[++tot]=i;
			for(int j=1;j<=t;j++)if(i%a[j]==0)st[tot]+=val[j];
		}
		memset(f,0,sizeof(f));
		f[0][0]=1;
		for(int i=1;i<=tot;i++){
			for(int T=0;T<=s;T++)if((T|s)==s){
				f[i][T]+=f[i-1][T];
				if(i^1)f[i][T|st[i]]+=f[i-1][T];
				f[i][T]%=P;
				f[i][T|st[i]]%=P;
			}
		}
		for(int i=0;i<=m;i++){
			int L=1;
			while(v[L+1]*q[i]<=n&&L+1<=tot)L++;
			h[i][s]=f[L][s];
			if(i&&s)h[i][s]=h[i][s]*2%P;
		}
	}
	int ans=0;
	for(int i=0;i<=m;i++){
		for(int s=0;s<1<<cnt;s++){
			for(int t=0;t<1<<cnt;t++)if(!(s&t)){
				if(!i){
					g[i][s][t]=h[0][s]*h[0][t]%P;
					continue;
				}
				g[i][s][t]+=g[i-1][s][t];
				g[i][s][t]%=P;
				for(int T=0;T<1<<cnt;T++){
					g[i][s|T][t]+=g[i-1][s][t]*h[i][T];
					g[i][s|T][t]%=P;
					g[i][s][t|T]+=g[i-1][s][t]*h[i][T];
					g[i][s][t|T]%=P;
				}
				if(i==m){
					ans+=g[i][s][t];
					ans%=P;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 0ms
memory: 6612kb

input:

2 1

output:

0

result:

ok single line: '0'

Test #2:

score: 10
Accepted
time: 1ms
memory: 6320kb

input:

13 12345

output:

3438

result:

ok single line: '3438'

Test #3:

score: 10
Accepted
time: 2ms
memory: 6600kb

input:

26 1000000000

output:

447212583

result:

ok single line: '447212583'

Test #4:

score: 10
Accepted
time: 3ms
memory: 7240kb

input:

99 90000001

output:

88114119

result:

ok single line: '88114119'

Test #5:

score: 10
Accepted
time: 0ms
memory: 6296kb

input:

50 19999991

output:

16185855

result:

ok single line: '16185855'

Test #6:

score: 10
Accepted
time: 4ms
memory: 8496kb

input:

144 1000000000

output:

108118957

result:

ok single line: '108118957'

Test #7:

score: 10
Accepted
time: 12ms
memory: 11768kb

input:

197 1200007

output:

132550

result:

ok single line: '132550'

Test #8:

score: 10
Accepted
time: 96ms
memory: 22036kb

input:

289 1200007

output:

1181263

result:

ok single line: '1181263'

Test #9:

score: 10
Accepted
time: 639ms
memory: 40500kb

input:

362 99991111

output:

81393435

result:

ok single line: '81393435'

Test #10:

score: 10
Accepted
time: 834ms
memory: 52752kb

input:

499 99999999

output:

7282170

result:

ok single line: '7282170'

Extra Test:

score: 0
Extra Test Passed