1 条题解
-
0严轶宸 LV 4 @ 2023-12-06 17:35:52
//清帝之惑之康熙
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;long long x,y,m,n,l;
void gcd(long long a,long long b,long long& d,long long & x,long long& y)
{
if(!b)
{
d=a;
x=1;
y=0;
}
else
{
gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}int main()
{
cin>>x>>y>>m>>n>>l;
long long a=((n-m)%l+l)%l;
long long b=l;
long long c=((x-y)%l+l)%l;
long long d;
gcd(a,b,d,x,y);
if(c%d)
cout<<"Impossible"<<endl;
else
{
long long a1=x*(c/d);
long long a2=abs(l/d);
while(a1<0)
a1+=a2;
while(a1-a2>=0)
a1-=a2;
cout<<a1<<endl;
}
return 0;
}
- 1