大体题意:

给你n 个数 x1,x3,,,x2n-1

让你确定出x2,x4,,,x2n来!

x数列每一项满足 xi = ((x(i-1) * a ) + b ) % 10001;

思路:

我们枚举a,因为对10001取模,所以a肯定在0~10000以内有解!

那么我们就枚举a,对于每一项a,我们根据x3和x1求出b来,然后开始枚举每一项看看这个a和b 是否合适!合适就输出终止枚举!

判断合适的方法是   跑一遍递推式,当发现与输入冲突时,不合适!  都不冲突 则合适!

这个题难点就在于如何求出b来!

这考察了 扩展欧几里得:

根据定义:

UVA 12169 Disgruntled Judge (扩展欧几里得)_C++

将x2代入x3得:

UVA 12169 Disgruntled Judge (扩展欧几里得)_#include_02

移向得:

UVA 12169 Disgruntled Judge (扩展欧几里得)_UVA_03

形如Ax + By = C的形式!

当C是gcd(A,B)的倍数时有解!

详细见代码:


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 10001;
ll x[mod],bb,n;
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); }
}
bool judge(ll a){
    ll A = mod;
    ll B = -(a+1);
    ll C = a*a*x[1] - x[3];
    ll g,xx,y;
    gcd(A,B,g,xx,y);
    if (C % g) return false;
    bb = y*C/g;
    for (int i = 2; i <= 2*n; ++i){
        if (i & 1){
            if (x[i] != (a*x[i-1]+bb)%mod) return false;
        }
        else {
            x[i] = (a*x[i-1]+bb)%mod;
        }


    }
    return true;
}
int main(){
    while(~scanf("%lld",&n)){
        for (int i = 1; i <= 2*n; i += 2) scanf("%lld",x+i);
        for (ll a = 0; a < mod; ++a){
            if (judge(a)){
                for (int i = 2; i <= 2*n; i += 2){
                    printf("%lld\n",x[i]%mod);
                }
                break;
            }
        }


    }

    return 0;
}