UVA - 12169 -扩展欧几里得算法
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> #define ll long long #define rep(i,j,k) for(int i=j;i<=k;++i) using namespace std; const int maxx = 1e4+7; ll a[maxx]; void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y) { if (!b) { d=a; x=1; y=0; } else { ex_gcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { int n; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); for (int i=1; i<=2*n; i+=2) { scanf("%lld",&a[i]); } ll d,k,b; rep(i,0,10000) { ex_gcd(10001,i+1,d,k,b); ll c=(a[3]-(ll)i*i*a[1]);//等式左边 b=b*c/d;//解数字解 if(c%d==0) { int flag; rep(j,2,2*n) { flag=1; ll tmp=(i*a[j-1]+b)%10001; if (j%2==1) { if (tmp!=a[j]) { flag=0; break; } }else { a[j]=tmp; } } if (flag) { break; } } else { continue; } } for (int i=2;i<=2*n;i+=2){ printf("%lld\n",a[i]); } } return 0; }
有不懂欢迎咨询
QQ:1326487164(添加时记得备注)