当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3931:Classmates

题目描述
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.
输入解释
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.
输出解释
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.
输入样例
1 1
3 3
53 9
100 2
999999999 999999999
0 0
输出样例
1
6
60
Impossible
2499999996

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3931

最后修改于 2020-10-29T07:15:51+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536