Description Two frogs met on the internet, they chatted very happy, so feel it is necessary to see one side. They were pleased to find that they lived on the same latitude line, so they agreed to jump westward until they met. But they forget a very important thing before they set out, neither to ask clearly the characteristics of each other, nor to meet the specific location. But the frogs are very optimistic, they feel as long as they have to jump in some direction, always meet each other. But unless the two frogs jump to the same point at the same time, they will never be able to meet. To help these two optimistic frogs, you are asked to write a procedure to determine if the two frogs will meet and when. We have these two frogs are called Frog A and Frog B, and the latitude line on the longitude of 0 degrees at the origin, from east to West for the positive direction, the unit length of 1 meters, so that we get a first-to-last line. The starting point of setting Frog A is x, and Frog B's starting point coordinates are Y. Frog A can jump M m at a time, Frog B can jump n meters at a time, and two frogs will spend the same time jumping once. Latitude line total length l m. Now you have to find out how many times they have jumped before they meet. Solution
Test instructions: Solving an equation (x+m*t)-(y+n*t) =KL
Conversion, equivalent to seeking (m-n) *t+kl=y-x
Direct expansion Euclidean need to find the solution of any one T, then adjust the minimum positive integer solution
It is worth noting that a possible solution to the expansion of the EU ans, the smallest nonnegative integer solution is ans= (ans%mod+mod)% mod, here directly to the X-mode (L/GDC), to ensure that the ANS can be as small as possible after the model, and then because C + + modulo equivalent to take the remainder, so the initial ans if Negative numbers, modulo will get a-(mod-1) to 0 of the number, this time with a mod and then modulo can get the least nonnegative solution, the smallest positive integer and then judge the following 0 can
1#include <map>2#include <cmath>3#include <ctime>4#include <queue>5#include <stack>6#include <cstdio>7#include <climits>8#include <iomanip>9#include <cstring>Ten#include <cstdlib> One#include <iostream> A#include <algorithm> - - #defineSet (a B) memset (A, (b), sizeof (a)) the #defineFR (i,a,b) for (ll i= (a), _end_= (b); i<=_end_;i++) - #defineRF (I,b,a) for (ll i= (a), _end_= (b); i>=_end_;i--) - #defineFe (I,A,B) for (int i=first[(b)],_end_= (a); i!=_end_;i=s[i].next) - #defineFEC (I,A,B) for (int &i=cur[(b)],_end_= (a); i!=_end_;i=s[i].next) + - using namespacestd; + AtypedefLong Longll; at -ll ans=0; - ll X,y,m,n,l; - - voidRead () - { in #ifndef Online_judge -Freopen ("1477.in","R", stdin); toFreopen ("1477.out","W", stdout); + #endif -Cin >> x >> y >> n >> m >>l; the } * $ voidWrite ()Panax Notoginseng { - if( !ans) thecout <<"Impossible" ; + Else Acout <<ans; the } + -ll EXGCD (ll a,ll b,ll &x,ll &y) $ { $ if(a==0 ){ -x=0, y=1; - returnb; the } -ll G=EXGCD (b%a,a,x,y);Wuyill k=y; they=x,x=k-b/a*x; - returnG; Wu } - About voidWork () $ { -ll A= (m-n), b=l,c=x-y; -ll gcd=EXGCD (a,b,x,y); - if(C%GCD)return ; AA/=gcd,b/=gcd,c/=gcd; +Ans= ((x*c)%b+b)%b; the if(!ans) ans=b/gcd; - } $ the intMain () the { the read (); the Work (); - write (); in return 0; the}
Bzoj 1477 date of the Frog