简单粗暴
模拟大法好
还以为会超时
但是
毕竟只是个第一题
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
#include<climits>
#include<string>
#include<cstdlib>
#include<ctime>
#define MOD 1000000007
#define LL long long
using namespace std;
LL t[100005];
LL n,m,ah,bh,a[200005],i,p,l,r,q[800005],d;
bool ex[100005];
int main()
{
scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&ah,&bh,&a[1],&a[2]);
p=n/2;
l=1;
r=2;
q[1]=a[1];
q[2]=a[2];
ex[a[1]]=1;
ex[a[2]]=1;
for(i=3;i<=m;i++)
{
if(i>p+1)
{
ex[q[l]]=0;
l++;
}
d=0;
t[0]=(ah*a[i-1]%n+bh*a[i-2]%n)%n;
while(ex[t[d]])
{
d++;
t[d]=(t[d-1]+1)%n;
}
r++;
q[r]=t[d];
a[i]=t[d];
ex[t[d]]=1;
}
for(i=3;i<=m;i++)
printf("%lld ",a[i]);
return 0;
}