시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB2411940.909%

문제

If a bag contains $r$ red balls and $g$ green balls and two balls are drawn at random, the probability of getting one ball of each color is $$ P(r, g) = \frac{2rg}{(r+g)(r + g - 1)} $$

Write a program which takes as input a rational number $p/q$ in lowest terms and determines whether there is a number $r \leq 10^6$ and a $g \geq r$ for which $P(r, g) = p/q$.

입력

The only line of input contains two space-separated positive integers $p$ ($p > 0$) and $q$ ($ 2p - 1 \leq q \leq 1000$). These two integers are guaranteed to be relatively prime.

출력

If there is a solution, print the two positive integers $r$ and $g$ satisfying the conditions above, separated by a space. If there are multiple solutions, output the one with the smallest $r$ value. For any $r$ value, there is at most one $g$ value ($g \geq r$), which solves $P(r,g) = p/q$. If there is no solution with $r \leq 10^6$, print the word impossible.

예제 입력 1

12 25

예제 출력 1

9 16

예제 입력 2

8 25

예제 출력 2

impossible

출처

ICPC > Regionals > North America > East Central North America Regional > 2025 East Central NA Regional Contest G번

  • 문제를 만든 사람: Fred Pickel