我该怎么说这道题呢。。。说简单其实也简单,就枚举模拟,开始卡了好久,今天看到这题没a又写了遍,看似会超时的代码交上去a了,果然实践是检验真理的唯一标准。。。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 const int mod = 10001 ; 7 8 int main (){ 9 int x[50005]; 10 int n; 11 while (~scanf ("%d",&n)){ 12 for (int i=1;i<2*n;i+=2) 13 scanf ("%d",&x[i]); 14 int a,b; 15 int flag; 16 for (a=0;a<=10000;a++){ 17 for (b=0;b<=10000;b++){ 18 int temp; 19 temp=(a*x[1]+b)%mod; 20 temp=(a*temp+b)%mod; 21 if (temp==x[3]) 22 break ; 23 } 24 //b=(x[3]-((a*a)%mod)*x[1]%mod)%mod/(a%mod+1); 25 flag=0; 26 for (int i=2;i<=2*n;i++){ 27 int temp=(a*x[i-1]+b)%mod; 28 if (i%2&&temp!=x[i]){ 29 flag=1; 30 break ; 31 } 32 x[i]=temp; 33 } 34 if (!flag) 35 break ; 36 } 37 for (int i=2;i<=2*n;i+=2) 38 printf ("%d ",x[i]); 39 } 40 return 0; 41 }