Problem 1902 --Problem E - Boastin' Red Socks

1902: Problem E - Boastin' Red Socks

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $4$ 正确数量 $3$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签

Problem E - Boastin' Red Socks

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".

1 2
6 8
12 2499550020
56 789
0 0
3 1
7 1
4 49992
impossible

推荐代码 查看1902 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] 计爱玲 350519 2018-12-19 10:15:30
内存最少[$0 $KB] 淡意的温柔 589231 2020-05-31 14:29:34
第一AC AOJ大管家 84417 2017-04-27 15:28:47
第一挑战 AOJ大管家 84417 2017-04-27 15:28:47

赛题来源/所属竞赛 NA N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛