中文题啊中文题,每次看到都是很兴奋的~
题目大意:自己看,全是中文~
解题思路:
对于题目可以列出:(x+m*s)-(y+n*s)=k*l;
整理得:(n-m)*s+k*l=x-y
s,k为未知数。可以用扩展GCD来解。
可以解的情况是当且仅当未知数系数的最大公因数可以去整除(x-y)的时候。
下面是代码:
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define eps 1e-6
#define pi acos(-1.0)
#define inf 107374182
#define inf64 1152921504606846976
#define lc l,m,tr<<1
#define rc m + 1,r,tr<<1|1
#define iabs(x) ((x) > 0 ? (x) : -(x))
#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (SIZE))
#define clearall(A, X) memset(A, X, sizeof(A))
#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))
#define memcopyall(A, X) memcpy(A , X ,sizeof(X))
#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )
#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )
using namespace std;
long long exgcd(long long m,long long n,long long &x,long long &y)
{
long long x1,y1,x0,y0;
x0=1; y0=0;
x1=0; y1=1;
x=0; y=1;
long long r=m%n;
long long q=(m-r)/n;
while(r)
{
x=x0-q*x1; y=y0-q*y1;
x0=x1; y0=y1;
x1=x; y1=y;
m=n; n=r; r=m%n;
q=(m-r)/n;
}
return n;
}
int main()
{
long long a,b,c,x,y,m,n,l,x1,x2,mod;
while(scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)!=EOF)
{
a=m-n;
b=l;
c=y-x;
if(a<0)
{
a=-a;
c=-c;
}
mod=exgcd(a,l,x1,x2);
l/=mod;
if(iabs(x-y)%mod)puts("Impossible");
else printf("%lld\n",((c/mod*x1)%l+l)%l);
}
return 0;
}