#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<stdlib.h>
#include<time.h>
#include <iomanip>
#define lowbit(x) (x&(-x))
#define inf 0x7fffffff
#define linf 0x7fffffffffffffff
#define fill(x,y) memset(x,y,sizeof(x))
#define fup(i,x,y) for(int i=(x);i<=(y);i++)
#define fdn(i,x,y) for(int i=(x);i>=(y);i--)
#define sp(x) setprecision(x)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define sc(n) scanf("%s",&n)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pff(x) printf("%lf\n",x)
//#define N 200005
#define M 4000009
#define mod 9973
#define pi acos(-1)
#define eps 1e-2
//cout.setf(ios::fixed);
//freopen("out.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef double db;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
ll d;
if(b==0) {x=1;y=0;b=0;return a;}
d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
int main()
{
ll x,y,m,n,l,d,x1,y1;
cin>>x>>y>>m>>n>>l;
if(m<n) swap(m,n),swap(x,y);
d=exgcd(m-n,l,x1,y1);
if((y-x)%d!=0) cout<<"Impossible"<<endl;
else
{
cout<<(x1*(y-x)/d%(l/d)+(l/d))%(l/d)<<endl;
}
return 0;
}
线性同余方程板子 poj 1061
最新推荐文章于 2019-05-30 21:20:57 发布