题目
首先想到的就是把乘除运算化为同一种,即对输入提前排好序
然后就是从大到小除……
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
unsigned long long a,b;
cin >> n;
while(n--)
{
int cnt = 0;
cin >> a >> b;
if(a == b){
printf("0\n");
continue;
}
else if(a > b){
swap(a,b);
}
if(b%a!=0){
cout << "-1" << endl;
continue;
}
unsigned long long s = b / a;
while(s % 8 == 0){
s = s / 8;
cnt++;
}
while(s % 4 == 0){
s = s / 4;
cnt++;
}
while(s % 2 == 0){
s = s / 2;
cnt++;
}
if(s!=1)
cout << -1 << endl;
else
cout << cnt << endl;
}
return 0;
}
另一种思路
学到了对样例的仔细分析