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 2T random numbers x1; : : : ; x2T between 0 and 10 000, and then writes T, followed by the 
 sequence x1; x3; x5; : : : ; x2T��1 to the input le, and the sequence x2; x4; x6; : : : ; x2T to the output le. 
 The random number generator the judge uses is quite simple. He picks three numbers x1, a, and b 
 between 0 and 10 000 (inclusive), and then for i from 2 to 2T lets xi = (a  xi��1 + b) mod 10001. 
 You may have thought that such a poorly designed problem would not be used in a contest of such 
 high standards as NWERC. Well, you were wrong. 
 Input 
 On the rst line one positive number: the number of testcases, at most 100. After that per testcase: 
  One line containing an integer n (0  n  10000): an input testcase. 
 The input le is guaranteed to be generated by the process described above. 
 Output 
 Per testcase: 
  One line containing an integer n (0  n  10000): an input testcase. 
 The input le is guaranteed to be generated by the process described above. 
 Output 
 Per testcase: 
  One line with an integer giving the answer for the testcase. 
 If there is more than one output le consistent with the input le, any one of these is acceptable.
Sample Input 
 3 
 17 
 822 
 3014
Sample Output 
 9727 
 1918 
 4110
【分析】 
 枚举a(毕竟a<=10000),通过递推式推导出s[1]与s[3]的关系,再通过exgcd解出b来,然后再循环判断一下是否成立。
【代码】
//UVa 12169 Disgruntled Judge
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mod=10001;
const int mxn=205;
int n,T,t,d;
int s[mxn];
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void exgcd(int a,int b,int &x,int &y)
{
if(b==0)
{
d=a,x=1,y=0;
return;
}
exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
int main()
{
int i,j,a,b,x,y,p,q;
T=read();
for(i=1;i<=2*T;i+=2)
s[i]=read();
fo(a,0,10000)
{
exgcd(a+1,mod,p,q);
if((s[3]-(long long)a*a*s[1])%d) continue;
b=(p*(s[3]-(long long)a*a*s[1])/d)%mod;
s[2]=(a*s[1]+b)%mod;
for(i=4;i<=2*T;i++)
{
int tmp=(((a*s[i-1])%mod)+b)%mod;
if(i&1 && tmp!=s[i]) break;
s[i]=tmp;
}
if(i==2*T+1)
{
for(i=2;i<=2*T;i+=2)
printf("%d\n",s[i]);
break;
}
}
return 0;
}
                










