//数据是有多水 连 10^10的枚举都能过
关于拓展欧几里德:大概就是x1=y2,y1=x2-[a/b]y2,按这个规律递归到gcd(a,0)的形式,此时公因数为a,方程也变为a*x+0*y=gcd(a,0)的形式,显然解为x=1,y=0,然后再递归回去就能得到解(a*x+b*y=gcd(a,b)的解)
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #include<stack> 11 #include<string> 12 13 using namespace std; 14 15 long long T; 16 long long x[201]; 17 18 void exGED(long long a,long long b,long long &d,long long &x,long long &y){ 19 if (b==0){ 20 x=1; 21 y=0; 22 d=a; 23 } 24 else{ 25 exGED(b,a%b,d,x,y); 26 long long tmp=x; 27 x=y; 28 y=tmp-(a/b)*y; 29 } 30 } 31 32 bool solve(long long a){ 33 long long d,b,k; 34 long long tmp=x[3]-a*a*x[1]; 35 exGED(a+1,10001,d,b,k); 36 if (tmp%d!=0) return false; 37 b=b*(tmp/d); 38 for (long long i=2;i<=2*T;i++){ 39 if (i%2==0){ 40 x[i]=(x[i-1]*a+b)%10001; 41 } 42 else{ 43 if (x[i]!=((x[i-1]*a+b)%10001)){ 44 return false; 45 } 46 } 47 } 48 for (long long i=2;i<=2*T;i+=2){ 49 printf("%I64d ",x[i]); 50 } 51 return true; 52 } 53 54 int main(){ 55 scanf("%I64d",&T); 56 for (long long i=1;i<2*T;i+=2){ 57 scanf("%I64d",&x[i]); 58 } 59 //solve(1096); 60 for (long long a=0;a<=10000;a++){ 61 if (solve(a)) break; 62 } 63 return 0; 64 } 65 /* 66 3 67 17 68 822 69 3014 70 */