题目链接:https://codeforces.com/contest/1141/problem/A
题意是输入a和b,a每次只能乘2乘3,问要乘多少次可以变为b。
思路就是如果b不能整除a肯定是不行的,又因为a只能乘2乘3,所以x = b / a中x的因子只能有2和3,如果出现别的因子就不行,可以直接除也可以搜索去写。
AC代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
int main()
{
scanf("%d%d",&n,&m);
if(m % n != 0){
puts("-1");
return 0;
}
int xx = m / n;
int cnt = 0;
while((xx % 2 == 0)){
if(xx % 2 == 0){
cnt ++;
xx /= 2;
}
}
while(xx % 3 == 0){
if(xx % 3 == 0){
cnt ++;
xx /= 3;
}
}
if(xx != 1)puts("-1");
else
cout<<cnt<<endl;
return 0;
}