编程介的小学生 2017-08-24 07:49 采纳率: 20.5%
浏览 749
已采纳

3456

Catherine, David, Edward and Frank are playing a guessing game. Each of them has different preference for number.

Catherine loves triangular number, such as 1, 3, 6, 10, and so on.

David is fond of square number, for example, 1, 4, 9, 16 are first four square numbers.

Edward is keen on pentagonal number, in the form like 1, 5, 12 and 22.

And number like 1, 6, 15, 28, which is called hexagonal number, is Frank's favorite.


Each of them guesses only their favorite numbers. After guessing, Everyone has a number to continue the game. In particular, one of Catherine's number, Edward's number and Frank's number is a multiple of the number David guesses.

The problem is, when you know Catherine's (or Edward's, Frank's) number is A times the number David guesses, to calculate minimal numbers of Catherine's (or Edward's, Frank's) and David's choices. To make the answer seems small, you should only to calculate the position of the number one guess in his or her series of favorite numbers. For example, you should output 1 when David guesses 1, output 2 when Frank guess 6, output 3 when Catherine guess 6, and output 4 when Edward guesses 22. Some detailed example will be shown in the next paragraph.

More specifically, when Catherine's number is 4 times David's, it's possible that Catherine guesses 36(=8*9/2) and David guesses 9(=3*3), or Catherine guesses 41616(= 288 * 289 / 2) and David guess 10404(=102*102), or they even guess greater. You need to consider the minimum possible solution only and the minimal numbers they can guess are 36 and 9, so your output should be 8 and 3. Another example, when Edward's number is 6 times David's, because a pentagonal number could not be 6 times a square number, you output should be "Impossible!" The last example in this paragraph, if Frank's number is 5 times David's, it's possible that Frank guesses 45(=5*9) and David guess 9(=3*3), or Frank guesses 93701205(=6845*13689=18740241*5) and David guess 18740241(=4329*4329), or they even guess greater. The solution is useful to us is 45 and 9, so your output is 5 and 3.

Input

Each case is a line containing two integers, p (p equals to 3, 5 or 6) and A (1≤ A≤ 1000000). p=3 means Catherine's number is A times David's. p=5 means Edward's number is A times David's. p=6 means Frank's number is A times David's.

A line with 0 only means end of the input.

Output

Each case a line, if the choice of the player who p implies can be A times David's, then you should output the positions of player p's guess and David's in corresponding favorite series, else output a string "Impossible!".

Sample Input

3 2
5 13
6 7
0
Sample Output

Impossible!
9 3
4 2

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-27 15:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行