#Q211. 「一本通 6.4 例 1」青蛙的约会
「一本通 6.4 例 1」青蛙的约会
Description
Original Source: POJ 1061
Two frogs met online and had a great conversation, so they decided to meet in person. They were delighted to find out that they lived on the same latitude line, so they agreed to jump westward until they met. However, they forgot something very important before setting off—they neither asked about each other's distinguishing features nor agreed on a specific meeting location. But frogs are optimistic creatures; they believed that as long as they kept jumping in a certain direction, they would eventually meet. Unless both frogs landed on the same point at the same time, they would never meet. To help these two optimistic frogs, you are asked to write a program to determine whether they can meet and, if so, after how many jumps.
We name the two frogs Frog A and Frog B and define the longitude line with 0 degrees east as the origin, the positive direction from east to west, and a unit length of 1 meter. This gives us a number axis that loops around. Let the starting coordinate of Frog A be and that of Frog B be . Frog A can jump meters per jump, and Frog B can jump meters per jump. Both frogs take the same amount of time for each jump. The total length of the latitude line is meters. Your task is to determine how many jumps they need to make before they meet.
Input Format
The input consists of a single line containing five integers , , , , and .
Output Format
Output the number of jumps required for them to meet. If it is impossible for them to meet, output Impossible.
Sample 1
1 2 3 4 5
4
Constraints & Hints
For of the data, , , and . It is guaranteed that .