Description
Two of the frogs met on the internet, and they chatted very happily, so they felt it was 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
2000000000,02000000000,02100000000.
Output
Output the number of hops required to meet, and output a line of "impossible" if it is never possible to meet
Sample Input
1 2 3 4 5
Sample Output
4
Source
Zhejiang
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> - using namespacestd; the #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) - #definell Long Long - #defineEPS 1e-10 + #defineMOD 1000000007 - #defineN 1000000 + #defineINF 1e12 A ll A,b,m,n,l; atll E_GCD (ll a,ll b,ll &x,ll &y) { - if(b==0) - { -x=1; -y=0; - returnA; in } -ll R=E_GCD (b,a%b,x,y); toll t=x; +x=y; -y=t-a/b*y; the returnR; * } $ intMain ()Panax Notoginseng { - while(SCANF ("%i64d%i64d%i64d%i64d%i64d", &a,&b,&m,&n,&l) = =5){ the ll X,y,r; +ll D=E_GCD ((nm), l,x,y); A //printf ("---%d%d%d\n", d,x,y); the if(A-B)%d!=0){ +printf"impossible\n"); - Continue; $ } $ Else{ -X=x* (A-B)/D; -r=l/D; thex= (x%r+r)%R; -printf"%i64d\n", x);Wuyi } the } - return 0; Wu}
View Code
POJ 1061 Frog Dating (extended Euclid)