51nod1429 巧克力
生活随笔
收集整理的這篇文章主要介紹了
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
?
轉載于:https://www.cnblogs.com/DriverLao/p/9074314.html
總結
以上是生活随笔為你收集整理的51nod1429 巧克力的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 再次学习mysql优化
- 下一篇: jpa实例