题目: LINK
题意:给定两个矩形a1*b1 和 a2*b2,每次操作是选择一个矩形对它水平或者垂直的 * 1/2, 或者 * 2/3必须整除,不能整除就无法进行。
要求最少的操作使得操作完的两个矩形的面积大小一样。
可以求出a1*b1 和 a2*b2 分别有多少个因子2, 和多少个因子3,除去这些因子剩下的部分这两者应该一样才可以,不一样的话NO。
之后如果一个数*2/3就相当于把它的因子3转换成2,如果*1/2就是消去一个因子2.
我们就把因子3多的那个数(*2/3)消去多余的因子3 同时生成新的因子2,之后两者因子3的个数一样多,之后就是(*1/2)去掉因子2多的那个数中多余的因子2,就可以了.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define INF 1000000000
typedef __int64 LL;
LL two1, three1, two2, three2;
LL a1, b1, a2, b2;
LL gao(LL ans, LL &two, LL &three) {
two = 0;
while(ans % 2 == 0) {
two ++;
ans /= 2;
}
three = 0;
while(ans % 3 == 0) {
three ++;
ans /= 3;
}
return ans;
}
void sol(LL &a, LL &b, LL del2, LL del3) {
while(a%3 == 0 && del3 != 0) {
a /= 3; del3--;
a *= 2;
}
while(b%3 == 0 && del3 != 0) {
b /= 3; del3--;
b *= 2;
}
while(a % 2 == 0 && del2 != 0) {
a /= 2; del2 --;
}
while(b %2 == 0 && del2 != 0) {
b /= 2; del2--;
}
}
int main() {
cin>>a1>>b1>>a2>>b2;
LL ans1 = a1 * b1;
LL ans2 = a2 * b2;
LL g1 = gao(ans1, two1, three1);
LL g2 = gao(ans2, two2, three2);
if(g1 != g2) {
puts("-1"); return 0;
}
LL ans = 0;
LL del13, del12, del23, del22;
del13 = del12 = del23 = del22 = 0;
ans += abs(three1 - three2);
if(three1 > three2) {
del13 = ans; two1 += ans;
}
else if(three1 < three2) {
del23 = ans; two2 += ans;
}
ans += abs(two1 - two2);
if(two1 > two2) del12 = two1 - two2;
else del22 = two2 - two1;
cout<<ans<<endl;
sol(a1, b1, del12, del13);
sol(a2, b2, del22, del23);
cout<<a1<<" "<<b1<<endl;
cout<<a2<<" "<<b2<<endl;
return 0;
}