题意:
给定公式xi=(xi-1*a+b)%10001
输入x1,x2,x3…..x2T-1,输出x2,x4,x6……x2T
思路:
枚举a[0,10000],通过扩展gcd计算出b
X2=(X1*a+b)%10001;
X3=(a*(X1*a+b)%10001+b)%10001;
X3=(a*(X1*a+b)+b)%10001;
X3+10001y=a*(X1*a+b)+b=X1*a*a+a*b+b
X3-X1*a*a=10001y-(1+a)b
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1000;
LL d,x,y;
LL data[maxn];
const int MOD = 10001;
void gcd(LL a,LL b,LL& d,LL& x,LL& y)
{
if(!b) {d=a;x=1;y=0;}
else {gcd(b,a%b,d,y,x);y-=x*(a/b);}
}
int main()
{
int T;
cin>>T;
for(int i=1;i<=2*T;i+=2)
{
cin>>data[i];
}
for(int a=0;a<=10000;a++)
{
LL t = data[3]-a*a*data[1];
gcd(MOD,a+1,d,x,y);
if(t%d) continue;
y=y/d*t;
bool flag=1;
for(int i=2;i<=2*T;i++)
{
LL tmp = (a*data[i-1]+y)%MOD;
if(i&1)
{
if(data[i]!=tmp)
{
flag=0;
break;
}
}
else
{
data[i]=tmp;
}
}
if(flag) {break;}
}
for(int i=2;i<=2*T;i+=2)
cout<<data[i]<<endl;
return 0;
}