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 files. 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 Ttest cases, the judge generates 2T random numbers x1, ..., x2T between 0 and 10000, and then writes T, followed by the sequence x1, x3, x5, ..., x2T-1 to the input file, and the sequence x2, x4, x6, ..., x2T to the output file.
The random number generator the judge uses is quite simple. He picks three numbers x1, a, and b between 0 and 10000 (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 first 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.
Output
Per testcase:- One line with an integer giving the answer for the testcase.
Sample Input
3 17 822 3014
Sample Output
9727 1918 4110
一.分析
main.cpp
UVa12169
Created by 张嘉韬 on 16/8/1.
Copyright © 2016年 张嘉韬. All rights reserved.
//
//#include <iostream>
//#include <cstring>
//#include <cstdio>
//#include <cmath>
//using namespace std;
//typedef long long ll;
//const int maxn=10000+10;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=0;
y=1;
return a;
}
ll r=exgcd(b,a%b,y,x);
y-=x*a/b;
return r;
}
//
//ll exgcd(ll a,ll b,ll &x,ll &y)
//{
// ll r,t;
// if(!b){ x=1; y=0; return a;}
// r=exgcd(b,a%b,x,y);
// t=x;
// x=y;
// y=t-a/b*y;
// return r;
//}
//int main(int argc, const char * argv[]) {
// freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin);
// int A[maxn]={0};
// int r[maxn]={0};
// int n;
// cin>>n;
// for(int i=1;i<=n;i++) cin>>A[i];
// for(int a=0;a;a++)
// {
// ll tc,g,b;
// int flag=1;
// g=exgcd(a+1,10001,b,tc);
// if((A[2]-a*a*A[1])%g!=0) continue;
// b=b*((A[2]-a*a*A[1])/g);
// b=(b%(10001/g)+(10001/g))%(10001/g);
// r[1]=(a*A[1]+b)%10001;
// for(int i=2;i<=n;i++)
// {
// if(A[i]!=(a*r[i-1]+b)%10001)
// {
// flag=0;
// break;
// }
// r[i]=(a*A[i]+b)%10001;
// }
// if(flag==0) continue;
// else break;
// }
// for(int i=1;i<=n;i++)
// {
// cout<<r[i]<<endl;
// }
// return 0;
//}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=10000+10;
//ll exgcd(ll a,ll b,ll &x,ll &y)
//{
// if(b==0)
// {
// x=0;
// y=1;
// return a;
// }
// ll r=exgcd(b,a%b,y,x);
// y-=(x*(a/b));
// return r;
//}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
ll r,t;
if(!b){ x=1; y=0; return a;}
r=exgcd(b,a%b,x,y);
t=x;
x=y;
y=t-a/b*y;
return r;
}
int main(int argc, const char * argv[]) {
freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin);
ll A[maxn]={0};
ll r[maxn]={0};
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>A[i];
for(int a=0;a<=10000;a++)
{
ll tc,g,b;
int flag=1;
g=exgcd(a+1,10001,b,tc);
if((A[2]-a*a*A[1])%g!=0) continue;
b=b*((A[2]-a*a*A[1])/g);
b=(b%(10001/g)+(10001/g))%(10001/g);
r[1]=(a*A[1]+b)%10001;
for(int i=2;i<=n;i++)
{
if(flag==0) break;
if(A[i]!=(a*r[i-1]+b)%10001)
{
//cout<<"shit"<<endl;
flag=0;
break;
}
r[i]=(a*A[i]+b)%10001;
}
if(flag==0) continue;
else break;
}
for(int i=1;i<=n;i++)
{
cout<<r[i]<<endl;
}
return 0;
}