编程介的小学生 2017-08-15 05:28 采纳率: 20.5%
浏览 699
已采纳

Classmates

Description

Mike graduated from high school several years ago. One day a question suddenly comes to his mind: how many classmates did he have in his high school? He doesn’t remember, and it's obviously too hard for him to recall everyone. But he does remember something - a game played on a New Year's Day. Because all his classmates had joined that game, Mike thinks he can figure out the number of his classmates by some clues.

The game went like this: At first, all classmates stood one by one in a circle, labeled clockwisely from No.1 to No. n. Of course n is the total number of all classmates. Then, starting from the No. 2 guy, they kicked out every 2nd guy. After each guy was kicked out, counting and kicking continued around the circle that remained, until there was only one guy left. That luck guy would get a gift. As shown in the picture below, if there were 6 classmates in the game, the people been kicked out would be in the order of No.2, No.4, No.6, No.3 and No.1, and in the end the No. 5 guy would win the gift.

Mike can only remember what number he was labeled, and how many classmates still remained in the circle when he was going to be kicked out. You should help him calculate the minimum possible total number of his classmates.
Input

The input consists of several cases. Every case is one line with two positive integer m and k(1<=m<=100,000,000, 1<=k<=100,000,000). m is Mike's number in the game, and k is the total number of people remained in the circle when Mike was going to be kicked out. (Mike was among those k people)

The input ends with a line containing two zero.
Output

For each test case, you should print the minimum possible total number of Mike’s classmates. If it’s impossible to find that number according to the input, please print "Impossible".
You may assume that the answer fits in a signed 64-bit integer.
Sample Input

1 1
3 3
53 9
100 2
999999999 999999999
0 0
Sample Output

1
6
60
Impossible
2499999996

  • 写回答

2条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型