#P1516. 青蛙的约会

    ID: 507 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学递归扩展欧几里德,扩欧中国剩余定理,CRT

青蛙的约会

Description

Two frogs met online and enjoyed chatting, so they thought it necessary to meet. They happily discovered that they live on the same line of latitude and agreed to jump westward until they meet. However, before setting off, they forgot something important: they neither asked each other's characteristics nor agreed on the exact meeting point. Still, the frogs are optimistic and believe that as long as they keep jumping in one direction, they will eventually meet. But unless both frogs land on the same point at the same time, they can never meet. To help these two optimistic frogs, you are asked to write a program to determine whether they can meet and when they will meet.

Call the two frogs frog A and frog B. On the latitude line, set the origin at 00^\circE, take the direction from east to west as positive, and set the unit length to 11 meter. In this way, we obtain a circular number line. Let the starting position of frog A be xx, and the starting position of frog B be yy. Frog A jumps mm meters per jump, and frog B jumps nn meters per jump. One jump takes the same time for both frogs. The total length of the latitude line is LL meters. Now you need to find after how many jumps they will meet.

Input Format

The input consists of one line with five integers x,y,m,n,Lx,y,m,n,L.

Output Format

Output the number of jumps needed for them to meet. If they can never meet, output a single line containing the string Impossible.

1 2 3 4 5

4

Hint

For 100%100\% of the testdata, 1x,y,m,n2×1091 \le x, y, m, n \le 2 \times 10^9, xyx \ne y, 1L2.1×1091 \le L \le 2.1 \times 10^9.

Translated by ChatGPT 5