找规律 SGU 126 Boxes

时间:2023-03-08 21:24:22
找规律 SGU 126 Boxes

题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126

 /*
找规律,智商不够,看了题解
详细解释:http://blog.csdn.net/ahfywff/article/details/7432524
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int GCD(int a, int b)
{
return b ? GCD (b, a % b) : a;
} int main(void) //SGU 126 Boxes
{
//freopen ("C.in", "r", stdin); int n, m; while (~scanf ("%d%d", &n, &m))
{
int ans;
if (n == || m == )
{
ans = ;
}
else
{
if (n < m) swap (n, m);
int k = GCD (n, m);
int x = n / k; int y = m / k;
if ((x+y) & )
{
ans = -;
}
else
{
int tmp = x + y;
ans = ;
while (tmp > )
{
if (tmp % == )
{
tmp /= ;
ans++;
}
else
{
ans = -; break;
}
}
}
} printf ("%d\n", ans);
} return ;
}