Chocolate

题意翻译

现在有两个块巧克力一块大小是 $a_1\times b_1$ 的,另外一块大小是 $a_2\times b_2$ 的。 现在要把两块巧克力变成面积一样大小,可以使用下列两种方法: - 可以沿横向或纵向的网格线分成两等分,然后吃掉其中的一份。 - 可以沿横向或纵向的网格线分成 $\dfrac23,\dfrac13$ 的两份,吃掉小的那一份。 因此使用第一种方法会留一半巧克力,用第二种方法会留下 $\dfrac23$ 巧克力。 两种方法并不总是可行的,有些时候两种方法都不能再用了。比如巧克力大小是 $16\times 23$ 的时候,可以使用第一种方法,但是不能使用第二种方法。当大小是 $20\times 18$的时候,可以使用第一种方法或者第二种方法。如果大小是 $5\times 7$ 的时候,两种方法都不能使用。 问最少要操作几次才能使得两块巧克力的面积是一样的,并输出巧克力可能的大小。 Translated by Eason_AC 2020.11.18

题目描述

Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is $ a_{1}×b_{1} $ segments large and the second one is $ a_{2}×b_{2} $ segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares. To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: - he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, - or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar. In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar. Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is $ 16×23 $ , then Polycarpus can chip off a half, but not a third. If the bar is $ 20×18 $ , then Polycarpus can chip off both a half and a third. If the bar is $ 5×7 $ , then Polycarpus cannot chip off a half nor a third. What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.

输入输出格式

输入格式


Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is $ a_{1}×b_{1} $ segments large and the second one is $ a_{2}×b_{2} $ segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares. To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: - he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, - or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar. In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar. Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is $ 16×23 $ , then Polycarpus can chip off a half, but not a third. If the bar is $ 20×18 $ , then Polycarpus can chip off both a half and a third. If the bar is $ 5×7 $ , then Polycarpus cannot chip off a half nor a third. What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.

输出格式


In the first line print $ m $ — the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in $ m $ minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them. If there is no solution, print a single line with integer -1.

输入输出样例

输入样例 #1

2 6
2 3

输出样例 #1

1
1 6
2 3

输入样例 #2

36 5
10 16

输出样例 #2

3
16 5
5 16

输入样例 #3

3 5
2 1

输出样例 #3

-1