QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406673#8543. Periodic SequencexiaolangRE 0ms0kbC++141.5kb2024-05-07 16:23:022024-05-07 16:23:03

Judging History

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

  • [2024-05-07 16:23:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-07 16:23:02]
  • 提交

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{
	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.5);
	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+500,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: 0
Dangerous Syscalls

input:

5 1000000007

output:


result: