当先锋百科网

首页 1 2 3 4 5 6 7

B - Game 23    CodeForces - 1141A 

Polycarp plays "Game 23". Initially he has a number nn and his goal is to transform it to mm. In one move, he can multiply nn by 22 or multiply nn by 33. He can perform any number of moves.

Print the number of moves needed to transform nn to mm. Print -1 if it is impossible to do so.

It is easy to prove that any way to transform nn to mm contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).

Input

The only line of the input contains two integers nn and mm (1≤n≤m≤5⋅1081≤n≤m≤5⋅108).

Output

Print the number of moves to transform nn to mm, or -1 if there is no solution.

Examples

Input

120 51840

Output

7

Input

42 42

Output

0

Input

48 72

Output

-1

Note

In the first example, the possible sequence of moves is: 120→240→720→1440→4320→12960→25920→51840.120→240→720→1440→4320→12960→25920→51840. The are 77 steps in total.

In the second example, no moves are needed. Thus, the answer is 00.

In the third example, it is impossible to transform 4848 to 7272.

 

题意:输入a,b;你可以对a进行*2或者*3,直到a= b,求要乘几次,如果无法实现直接输出-1

思路:用b/a得到一个t,再对t做除2,除3处理,直到不能除了位置,再判断最后是不是2或3(如果b不是a的倍数可直接输出-1)

代码:

#include <bits/stdc++.h>
using namespace std;
#define M 200010
int n,m,ans;

int main()
{
	cin>>n>>m;
	if(m%n!=0){
		cout<<-1<<endl;
		return 0;
	}
	if(m==n){
		cout<<0<<endl;
		return 0;
	}
	ans = 0;
	int a = m/n;	
	while(a%2==0&&a!=2){
 		a = a/2;
 		ans++;
	}
	while(a%3==0&&a!=3){
		a = a/3;
		ans++;
	}
	if(a==2||a==3){
		cout<<ans+1<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}