Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 94174 | Accepted: 17412 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
#include<stdio.h> #define LL __int64 void exgcd(LL a,LL b,LL &d,LL &x,LL &y) { if(!b)d=a,x=1,y=0; else { exgcd(b,a%b,d,y,x); y-=x*(a/b); } } LL gcd(LL a,LL b) { if(!b) return a; else gcd(b,a%b); } int main() { LL xx,yy,m,n,l; while(scanf("%I64d%I64d%I64d%I64d%I64d",&xx,&yy,&m,&n,&l)!=EOF) { LL d,x,y; LL aa,bb,cc,mm; aa=n-m; bb=l; cc=xx-yy; exgcd(aa,bb,d,x,y); // printf("%I64d %I64d %I64d\n",d,x,y); if(cc%d) printf("Impossible\n"); else { x=x*(cc/d); mm=bb/d; x=(x%mm+mm)%mm; printf("%I64d\n",x); } } return 0; }
原文:http://www.cnblogs.com/yuyixingkong/p/4372696.html