Tag Archives: SGU126

SGU 126 解题报告

http://acm.sgu.ru/problem.php?contest=0&problem=126

126. Boxes

time limit per test: 0.50 sec.
memory limit per test: 4096 KB

There are two boxes. There are A balls in the first box, and B balls in the second box (0 < A + B < 2147483648). It is possible to move balls from one box to another. From one box into another one should move as many balls as the other box already contains. You have to determine, whether it is possible to move all balls into one box.

现在有两个盒子。第一个盒子有A个球,另一个盒子有B个球 (0 < A + B < 2147483648).有一种移动球的方式.从一个盒子移动球到另一个盒子,但要求被移动的球的数量要与另一个盒子已有的球的数量相同.你必须算出是否有可能将其中一个盒子清空。

Input

The first line contains two integers A and B, delimited by space.

第一行包含两个整数 A 和 B,以空格隔开.

Output

First line should contain the number N - the number of moves which are required to move all balls into one box, or -1 if it is impossible.

第一行输出整数 N -如果可以清空其中一个盒子所需要的移动次数,如果不可能,则输出-1.

Read more »