求二元一次不定方程
#include<iostream>
#include<cstring>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b)
{
return a==0?b:gcd(b,a%b);
}
ll extgcd(ll a,ll b,ll &x,ll &y)
{
if(b==0) {x=1;y=0;return a;}
ll d=extgcd(b,a%b,x,y);
ll t=x; x=y;y=t-a/b*y;
return d;
}
int main ()
{
ll x,y,m,n,l;
cin>>x>>y>>m>>n>>l;
ll a=m-n;
ll b=y-x;
if(a<0)
{
a*=-1;
b*=-1;
}
ll xx,yy;
ll gcdd=extgcd(a,l,xx,yy);
if(b%gcdd==0)
{
cout<<((xx*(b/gcdd))%(l/gcdd)+(l/gcdd))%(l/gcdd);
}
else cout<<"Impossible";
}