Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <cstdio>#include <cstring>typedef long long ll;ll gcd(ll a,ll b){ll t;while(t=a%b){a=b;b=t;}return b;}void ex_gcd(ll a,ll b,ll d,ll& x,ll& y){if(!b){d=a;x=1;y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}int main() {int s1,s2,v1,v2,m;while(scanf("%d%d%d%d%d",&s1,&s2,&v1,&v2,&m)==5){ll a=v1-v2,b=m,c=s2-s1;if(a<0) a+=m;ll d=gcd(a,b);if(c%d){printf("-1\n");