# Codeforces Round #653 (Div. 3) B. Multiply by 2, divide by 6（暴力、思维）

## Multiply by 2, divide by 6

#include <iostream>
using namespace std;
typedef long long ll;

int main() {
int t;
cin >> t;
while(t--) {
ll n, s = 0;
cin >> n;
while(1) {
if(n % 3 && n % 6) //如果出现不能整除的情况，之后就一定不能得到1了（因为操作时*2或者/6，如果不满足不论怎么操作都不会满足）
break;
if(n == 1)
break;
if(n % 6 == 0){
n /= 6;
s++;
}else if(n % 3 == 0) {	//n *= 2， n /= 6；
n /= 3;
s += 2;
}
}

if(n == 1)
cout << s << endl;
else
cout << "-1" << endl;
}

return 0;
}

### 原题：

You are given an integer n. In one move, you can either multiply n by two or divide nn by 6 (if it is divisible by 6 without the remainder).

Your task is to find the minimum number of moves needed to obtain 1 from nn or determine if it's impossible to do that.

You have to answer tt independent test cases.

The first line of the input contains one integer tt (1≤t≤2⋅10^4) — the number of test cases. Then tt test cases follow.

The only line of the test case contains one integer nn (1≤n≤10^9).

For each test case, print the answer — the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.

Input：                 Output:

7
1 ------------------------- 0
2 ------------------------- -1
3 ------------------------- 2
12 ------------------------ -1
12345 ------------------- -1
15116544 -------------- 12
387420489 ------------ 36

Note:

Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 1511654415116544 :

1. Divide by 66 and get 25194242519424 ;
2. divide by 66 and get 419904419904 ;
3. divide by 66 and get 6998469984 ;
4. divide by 66 and get 1166411664 ;
5. multiply by 22 and get 2332823328 ;
6. divide by 66 and get 38883888 ;
7. divide by 66 and get 648648 ;
8. divide by 66 and get 108108 ;
9. multiply by 22 and get 216216 ;
10. divide by 66 and get 3636 ;
11. divide by 66 and get 66 ;
12. divide by 66 and get 11 .

06-29 74

#### Codeforces Round #653 (Div. 3)(A~E)

06-29 24

#### Codeforces Round #653 (Div. 3) B.Multiply by 2, divide by 6(数学) 06-29 114

#### Codeforces Round #653 (Div. 3)部分题解

05-07 274

#### D. Divide by three, multiply by two（div3）

06-29 173

#### [codeforces 1374B] Multiply by 2, divide by 6 统计3的幂次+统计2的幂次

06-29 243

#### Codeforces Round #653 (Div. 3)A-B-C-D-E1

05-20 121

#### 每日一题之 Divide by three, multiply by two

05-07 1111

#### Divide by three, multiply by two ( 深搜 )

06-29 209

#### Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)

06-29 102

#### Codeforces Round #653 (Div. 3) A、B、C、D、E1题解

06-29 1486

#### Codeforces Round #653 (Div. 3)(A 二分 B 水 C 水 D 水 E1 思维 F 模拟 得到有序数组 )

06-29 32

#### Codeforces Round #653 (Div. 3) B ~ E1题解

06-05 110

#### Codeforces Round #647 (Div. 2)

06-29 36

#### Codeforces Round #653 (Div. 3)

05-07 65

#### Codeforces Round #479 (Div. 3) D - Divide by three, multiply by two

06-05 285

#### 【CodeForces】CodeForces Round #485 (Div. 1 + Div. 2) 题解

06-30 26

#### Codeforces Round #653 (Div. 3) C. Move Brackets（思维）

03-20 402

#### Codeforces Round #547 (Div. 3) ©️2020 CSDN 皮肤主题: 黑客帝国 设计师: 上身试试 点击重新获取   扫码支付 1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。 余额充值