QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291072#2858. 序列计数MoRanSky100 ✓87ms29184kbC++141.2kb2023-12-26 04:44:222023-12-26 04:44:23

Judging History

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

  • [2023-12-26 04:44:23]
  • 评测
  • 测评结果:100
  • 用时:87ms
  • 内存:29184kb
  • [2023-12-26 04:44:22]
  • 提交

answer

// luogu-judger-enable-o2
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=20170408;
int n,m,p,tot,ret;
int A[105],B[105],ans[105],prime[10000005];
bool fl[20000005];

int mod(int x){return x>=p?x-p:x;}

void mul(int *A,int *B,int *C){
	memset(ans,0,sizeof(ans));
	for(int i=0;i<p;i++) for(int j=0;j<p;j++) ans[mod(i+j)]=(ans[mod(i+j)]+1ll*B[i]*C[j]%cys)%cys;
	for(int i=0;i<p;i++) A[i]=ans[i];
}

void solve(int p){for(;p;p>>=1,mul(B,B,B)) if(p&1) mul(A,A,B);}

void getprime(int g){
	fl[1]=true;
	for(int i=2;i<=g;i++){
		if(!fl[i]) prime[++tot]=i;
		for(int j=1;j<=tot&&i*prime[j]<=g;j++){
			fl[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
}

int main(){
	n=readint(); m=readint(); p=readint();
	getprime(m);
	for(int i=0;i<p;i++) A[i]=B[i]=m/p+(m%p>=i)-(i==0);
	solve(n-1);
	ret=A[0];
//	cout<<"TEST "<<ret<<endl;
	for(int i=0;i<p;i++) A[i]=B[i]=m/p+(m%p>=i)-(i==0);
	for(int i=1;i<=m;i++) if(!fl[i]) A[i%p]--,B[i%p]--;
	solve(n-1);
	printf("%d\n",(ret-A[0]+cys)%cys);
	return 0;
}

详细

Test #1:

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

input:

59 74 92

output:

12897479

result:

ok single line: '12897479'

Test #2:

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

input:

69 67 96

output:

1349436

result:

ok single line: '1349436'

Test #3:

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

input:

943671998 73 85

output:

18207212

result:

ok single line: '18207212'

Test #4:

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

input:

746634527 62 94

output:

17351056

result:

ok single line: '17351056'

Test #5:

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

input:

564722714 95 81

output:

2784012

result:

ok single line: '2784012'

Test #6:

score: 10
Accepted
time: 6ms
memory: 8564kb

input:

611369852 733282 81

output:

18549852

result:

ok single line: '18549852'

Test #7:

score: 10
Accepted
time: 5ms
memory: 7912kb

input:

844122870 626526 95

output:

15263765

result:

ok single line: '15263765'

Test #8:

score: 10
Accepted
time: 5ms
memory: 7868kb

input:

502354839 648479 83

output:

10550324

result:

ok single line: '10550324'

Test #9:

score: 10
Accepted
time: 87ms
memory: 29184kb

input:

594910299 19953853 95

output:

14988503

result:

ok single line: '14988503'

Test #10:

score: 10
Accepted
time: 85ms
memory: 29020kb

input:

504926671 19227699 90

output:

6598138

result:

ok single line: '6598138'