不存在的泳池

http://icpc.upc.edu.cn/problem.php?cid=1721&pid=4 

#include
#include
#include
#include
#include
using namespace std;
long long a,b,l1,k,kk,l2,l3,l4,ans,k1,k2,k3,k4;
int gcd(int a,int b)
{
    if (b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    while (~scanf("%lld%lld",&a,&b))
    {
        k1=k2=k3=k4=l4=l1=l2=l3=0;
        while (a%2==0)
        {
            k1++;
            a=a/2;
        }
        while (a%3==0)
        {
            k2++;
            a=a/3;
        }
        while (b%2==0)
        {
            k3++;
            b=b/2;
        }
        while (b%3==0)
        {
            k4++;
            b=b/3;
        }
        if (a!=b)
        {
            printf("-1\n");
        }
        else
        {
            printf("%lld\n",abs(k1-k3)+abs(k2-k4));
        }
    }
}

 

你可能感兴趣的:(不存在的泳池)