标签:
http://poj.org/problem?id=1061
题意:裸题。注意负数。
//poj1061 #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; typedef long long LL; LL tx,ty; LL exgcd(LL a,LL b) { if(b==0) {tx=1,ty=0;return a;} LL d=exgcd(b,a%b); LL x=ty,y=tx-(a/b)*ty; tx=x;ty=y; return d; } int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); LL x,y,m,n,l; scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l); LL g=exgcd(m-n,l); // printf("g = %I64d\n",g); if((y-x)%g!=0) printf("Impossible\n"); else { LL rx=tx*(y-x)/g; LL r=l/g; if(r<0) r*=-1; rx=(rx%r+r)%r; printf("%I64d\n",rx); } return 0; }
标签:
原文地址:http://www.cnblogs.com/KonjakJuruo/p/5178505.html