UVA 12169 不爽的裁判

#include<iostream>
#include<string>
#include<string>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#define maxn 210
using namespace std;
typedef long long LL;

void gcd(LL a , LL b ,LL &d, LL &x,LL &y){
    if(!b){
        d = a ;
        x = 1;  y = 0;
        return ;
    }
    else{
        gcd(b , a % b ,d , y , x);
        y -= x * (a / b);
        return ;
    }
}
int main(){
    LL  f[maxn],a,b,k;
    int flag,t;
   cin>>t;
    memset(f,0,sizeof(f));
    for(int i=1;i<2*t;i+=2){
        cin>>f[i];
    }
    for(int i=0;i<=10000;i++){
        a=i;flag=1;
        LL k , b , d;
        LL c = (f[3] - a * a * f[1]);
        gcd(10001, a + 1, d , k, b);
        if(c% d) continue;
        b = b * c / d;
            for(int j=2;j<=2*t;j++){
               if(j&1){
                if(f[j]!=((a*f[j-1]+b)%10001)){
                    flag=0;
                    break;
                 }
               }else{
                   f[j]=(a*f[j-1]+b)%10001;
               }
            }
            if(flag)
                break;

     }
            for(int j=2;j<=2*t;j+=2){
                    cout<<f[j]<<endl;
                }

   return 0;
}

 

posted @ 2016-03-09 18:52  咸咸的告别  阅读(450)  评论(0编辑  收藏  举报