306065: CF1141A. Game 23

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:12 Solved:0

Description

Game 23

题意翻译

给出两个数 $n,m (1 \le n \le m \le 5 \cdot 10^{8})$ 询问能否通过将 $n$ 乘 $2$ 和将 $n$ 乘 $3$ 两种操作使 $n$ 变为 $m$ ,如果可行,输出最小操作次数,如果不可行,输出 $-1$

题目描述

Polycarp plays "Game 23". Initially he has a number $ n $ and his goal is to transform it to $ m $ . In one move, he can multiply $ n $ by $ 2 $ or multiply $ n $ by $ 3 $ . He can perform any number of moves. Print the number of moves needed to transform $ n $ to $ m $ . Print -1 if it is impossible to do so. It is easy to prove that any way to transform $ n $ to $ m $ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).

输入输出格式

输入格式


The only line of the input contains two integers $ n $ and $ m $ ( $ 1 \le n \le m \le 5\cdot10^8 $ ).

输出格式


Print the number of moves to transform $ n $ to $ m $ , or -1 if there is no solution.

输入输出样例

输入样例 #1

120 51840

输出样例 #1

7

输入样例 #2

42 42

输出样例 #2

0

输入样例 #3

48 72

输出样例 #3

-1

说明

In the first example, the possible sequence of moves is: $ 120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840. $ The are $ 7 $ steps in total. In the second example, no moves are needed. Thus, the answer is $ 0 $ . In the third example, it is impossible to transform $ 48 $ to $ 72 $ .

Input

题意翻译

给出两个数 $n,m (1 \le n \le m \le 5 \cdot 10^{8})$ 询问能否通过将 $n$ 乘 $2$ 和将 $n$ 乘 $3$ 两种操作使 $n$ 变为 $m$ ,如果可行,输出最小操作次数,如果不可行,输出 $-1$

加入题单

上一题 下一题 算法标签: