Once upon a time, there was an NWERC judge with a tendency to create
slightly too hard problems. As a result, his problems were never
solved. As you can image, this made our judge somewhat frustrated.
This year, this frustration has culminated, and he has decided that
rather than spending a lot of time constructing a well-crafted
problem, he will simply write some insanely hard problem statement and
just generate some random input and output les. After all, why bother
having proper test data if nobody is going to try the problem anyway?
Thus, the judge generates a testcase by simply letting the input be a
random number, and letting the output be another random number.
Formally, to generate the data set with T test cases, the judge
generates 2 T random numbers x 1 ; : : : ; x 2 T between 0 and 10 000,
and then writes T , followed by the sequence x 1 ; x 3 ; x 5 ; : : : ;
x 2 T
枚举a,然后O(n)时间判断是否可行,总复杂度O(n*MOD)。
判断的时候,联立
ax1+b=x2(mod 10001)
ax2+b=x3(mod 10001)
得(a+1)b+10001k=x3-a^2*x1
用扩展欧几里得算法解出b,然后验证即可。
#include<cstdio>
#include<cstring>
const int mod=10001;
int f[110],g[110],n;
void euc(int a,int b,int &d,int &x,int &y)
{
if (b==0)
{
d=a;
x=1;
y=0;
return;
}
euc(b,a%b,d,y,x);
y-=x*(a/b);
}
int main()
{
int i,j,k,m,p,q,x,y,z,x1,x2,x3,a,b,d;
bool flag;
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&f[i]);
for (a=0;a<mod;a++)
{
euc(a+1,mod,d,p,q);
if ((f[2]-(long long)a*a*f[1])%d) continue;
b=(p*(f[2]-(long long)a*a*f[1])/d)%mod;
flag=1;
g[1]=(f[1]*a+b)%mod;
for (i=2;i<=n;i++)
{
if (f[i]!=(g[i-1]*a+b)%mod)
{
flag=0;
break;
}
g[i]=(f[i]*a+b)%mod;
}
if (flag)
{
for (i=1;i<=n;i++)
printf("%d\n",g[i]);
return 0;
}
}
}