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

### Input

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

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

2 6

2

a->a/gcd(a,b)
b->b/gcd(a,b)
if a+b=2^k then
print k
else
print -1

### CODE

#include
int gcd(int a,int b)
{
int r;
while(b){
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
int a,b,c,k;
scanf("%d%d",&a,&b);
c=gcd(a,b);
a/=c;b/=c;
a+=b;
b=1;k=0;
while(ba||b<0){
printf("-1n");
return 0;
}
}
return 0;
}