51nod1429 巧克力

【题解】

  找一下两个面积s1,s2的2和3的因子数,把他们除掉,如果s1,s2不相等,就是-1,否则可以用s1,s2的2和3的因子数计算答案。

  

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define LL long long 
 4 #define rg register
 5 using namespace std;
 6 LL t1,t2,a2,a3,b2,b3,ans;
 7 inline int read(){
 8     int k=0,f=1; char c=getchar();
 9     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
10     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
11     return k*f;
12 }
13 int main(){
14     t1=1ll*read()*read(); t2=1ll*read()*read();
15     while(t1%2==0) a2++,t1>>=1;
16     while(t1%3==0) a3++,t1/=3;
17     while(t2%2==0) b2++,t2>>=1;
18     while(t2%3==0) b3++,t2/=3;
19     if(t1!=t2){
20         puts("-1"); return 0;
21     }
22     ans=abs(a3-b3);
23     if(a3<b3) b2+=ans; else a2+=ans;
24     ans+=abs(a2-b2);
25     printf("%lld\n",ans);
26     return 0;
27 }
View Code

 

posted @ 2018-05-22 21:48  Driver_Lao  阅读(209)  评论(0编辑  收藏  举报