1477: The frog's date time limit:2 Sec Memory limit:64 MB
submit:261 solved:164
[Submit] [Status] [Discuss] 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. Input inputs include only one line of 5 integer x,y,m,n,l, where X≠y < 2000000000,0 < M, n < 2000000000,0 < L < 2100000000. Output output The number of hops required to meet, and if it is never possible to meet then outputs a line of "impossible" Sample Input1 2 3) 4 5
Sample Output4
HINT Source
The problem: The classic extension of the euro a few calculation, remember the wrong words I seem to poj on a over this question = =
1/**************************************************************2Problem:14773 User:hansbug4 language:pascal5 result:accepted6Time:0Ms7Memory:224KB8****************************************************************/9 Ten type OneVec=Record A X,y:int64; - End; - var the I,j:longint; - K,l,m,n,x,y,x1,x2,x3:int64; - A1,a2:vec; - functionEX_GCD (A,b:int64): VEC; + var - A1,a2:vec; + begin A ifb=0 Then at begin -a1.x:=1; a1.y:=0; -ex_gcd:=A1 - End - Else - begin inA1:=EX_GCD (b,aMoDb); -a2.x:=a1.y; toA2.y:=a1.x-(ADivb) *a1.y; +ex_gcd:=A2; - End; the End; * functiongcd (X,y:int64): Int64; $ varPanax Notoginseng Z:int64; - begin the whileY<>0 Do + begin AZ:=xMoDy; thex:=y; +y:=Z; - End; $gcd:=x; $ End; - begin - readln (x,y,m,n,l); theA1:=EX_GCD (m-n,-l); -K:=GCD (m-n,-l);Wuyi if((Y-x)MoDK) <>0 Then the begin -Writeln ('Impossible'); Wu Halt; - End; Aboutx1:= (Y-x)DivK; $a1.x:=a1.x*X1; -a1.y:=a1.y*X1; - ifA1.x>0 Thena1.x:=a1.xMoDLElseA1.x:= ((a1.xMoDL) +2*L)MoDl; - Writeln (a1.x); A End.
1477: the frog's date