QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406670#8543. Periodic SequencexiaolangTL 1ms3848kbC++142.3kb2024-05-07 16:20:562024-05-07 16:21:01

Judging History

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

  • [2024-05-07 16:21:01]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3848kb
  • [2024-05-07 16:20:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e6+5;
int n,MOD;
int cc[N];
int anss[N];
int tar[N];
int inv[N];
int cnt=0;
namespace Polynomial{
	int cc[N];
	void mul(vector<pair<int,int> > a,vector<pair<int,int> > b){
		int lena=a.size();
		int lenb=b.size();
		for(int i=0;i<=n;i++){
			cc[i]=0;
		}
		for(int i=0;i<lena;i++){
			for(int j=0;j<lenb;j++){
				anss[a[i].first+b[j].first]=(anss[a[i].first+b[j].first]+(long long)a[i].second*b[j].second%MOD)%MOD;
			}
		}
	}
	vector<pair<int,int> > mulinv(vector<pair<int,int> > x){
		int xlen=x.size();
		for(int i=0;i<=n;i++){
			cc[i]=0;
			tar[i]=0;
		}
		tar[0]=1;
		vector<pair<int,int> >ans;
		for(int i=0;i<=n;i++){
			if(cc[i]==tar[i])continue;
			else{
				cnt++;
				int nowc=(cc[i]-tar[i]+MOD)%MOD;
				ans.push_back(make_pair(i,nowc));
				for(int j=0;j<xlen;j++){
					cc[i+x[j].first]=(cc[i+x[j].first]+(long long)nowc*x[j].second%MOD)%MOD;
				}
			}
		}
		return ans;
	}
	vector<int> div(vector<int> c){/* /(2x-1) */
		vector<int>ans;
		ans.clear();
		int len=c.size();
		for(int i=0;i<len;i++){
			int t=(MOD-c[i])%MOD;
			ans.push_back(t);
			if(i!=len-1)c[i+1]=((long long)c[i+1]-2*t+MOD+MOD)%MOD;
		}
		return ans;
	}
	void div2(vector<int> c,int p){/* /(-x^p+2x-1) */
		int len=c.size();
		for(int i=0;i<len;i++){
			int t=(MOD-c[i])%MOD;
			anss[i]=(anss[i]+t)%MOD;
			if(i!=len-1)c[i+1]=((long long)c[i+1]-2*t+MOD+MOD)%MOD;
			if(i+p<len)c[i+p]=(c[i+p]+t)%MOD;
		}
	}
};
using namespace Polynomial;
vector<int> fz;
int maxdep=0;
int addlen=0;
int main(){
	//freopen("1.txt","r",stdin);
	//freopen("1.out","w",stdout);
	//int tim1=clock();
	scanf("%d%d",&n,&MOD);
	int B=pow(n,0.45);
	fz.resize(n+2);
	for(int i=1;i<=B;i++){
		for(int j=0;j<=n;j++)fz[j]=((j==i)?(MOD-1):0);
		div2(fz,i+1);
	}
	int tim3=clock();
	vector<int>ans(n+1000,0);
	for(int i=n/B+1;i>=1;i--){
		for(int j=B+1;j*i-1<=n;j++){
			ans[j*i+i-1]=(ans[j*i+i-1]-1+MOD)%MOD;
		}
		ans=div(ans);
	}
	//int tim4=clock();
	//cout<<tim4-tim3<<"\n";
	//int tim4=clock();
	//cout<<tim3-tim1<<"\n";
	int tot=0;
	for(int i=1;i<=n;i++){
		//cout<<ans[i]<<" "<<anss[i]<<"\n";
		cout<<(ans[i]+anss[i])%MOD<<" ";
	}
	cout<<"\n";
	//int tim2=clock();
	//cout<<tim2-tim1<<"\n";
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3848kb

input:

5 1000000007

output:

1 3 6 11 19 

result:

ok 5 number(s): "1 3 6 11 19"

Test #2:

score: -100
Time Limit Exceeded

input:

200000 567894337

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 195106662 344669981 35619335 477103886 79913732 147415830 329955039 273123672 546045352 337527455 443978690 4597...

result: