Logo
(追記) (追記ここまで)

4410번 - Boastin' Red Socks 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB82302230.556%

문제

You have a drawer that is full of two kinds of socks: red and black. You know that there are at least 2 socks, and not more than 50000. However, you do not know how many there actually are, nor do you know how many are red, or how many are black. (Your mother does the laundry!)

You have noticed, though, that when you reach into the drawer each morning and choose two socks to wear (in pitch darkness, so you cannot distinguish red from black), the probability that you pick two red socks is exactly p/q, where 0 < q and 0 <= p <= q.

From this, can you determine how many socks of each colour are in your drawer? There may be multiple solutions - if so, pick the solution with the fewest total number of socks.

입력

Input consists of multiple problems, each on a separate line. Each problem consists of the integers p and q separated by a single space. Note that p and q will both fit into an unsigned long integer.

Input is terminated by a line consisting of two zeroes.

출력

For each problem, output a single line consisting of the number of red socks and the number of black socks in your drawer, separated by one space. If there is no solution to the problem, print "impossible".

If there are multiple solutions with the fewest total number of socks, pick the solution with the fewest number of red socks.

제한

예제 입력 1

1 2
6 8
12 2499550020
56 789
0 0

예제 출력 1

3 1
7 1
4 49992
impossible

힌트

출처

Contest > Waterloo's local Programming Contests > 19 June, 1999 E번

  • 빠진 조건을 찾은 사람: dotorya
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /