解题报告:
果A大于B那么显然无解。
考虑把A和B分解质因数。
若B存在A没有的质因数也显然无解。
对于某一个A的质因数的次数。为了加速接近B,它一定是每次翻倍,最后一次的时候把剩下的加上。
那么答案就是最小的k使得2k∗Anum≥Bnum。
最后把每个质因数的答案max起来即可。
感觉本场比赛没有trick(雾~),我就打算加入一个很经典的trick:
B可以刚好等于263,这样就要开unsigned long long。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
LL gcd(LL a,LL b)
{
if(a%b)
return gcd(b,a%b);
return b;
}
int main()
{
LL t;
scanf("%lld",&t);
while(t--)
{
LL n,m;
scanf("%I64d%I64d",&n,&m);
LL cnt=0;
while(n!=m)
{
if(m%n)
{
printf("-1\n");
break;
}
LL k=gcd(n,m/n);
if(k==1)
{
printf("-1\n");
break;
}
n*=k;
cnt++;
}
if(m==n)
printf("%I64d\n",cnt);
}
return 0;
}