1
+ /*
2
+ *** In The Name Of GOD ***
3
+ author: AliBinary
4
+ Email: AliGhanbariCs@gmail.com
5
+ GitHub: https://github.com/AliBinary
6
+ created: 21.11.2024 22:19:37
7
+ */
8
+
9
+ #include < bits/stdc++.h>
10
+ using namespace std ;
11
+
12
+ #define endl ' \n '
13
+ #define sep ' '
14
+ typedef long long ll;
15
+ typedef long double ld;
16
+ typedef string str;
17
+
18
+ // pairs
19
+ typedef pair<ll, ll> pll;
20
+ typedef pair<int , int > pii;
21
+ #define F first
22
+ #define S second
23
+ #define mp make_pair
24
+
25
+ #define tcT template <class T
26
+ tcT > using V = vector<T>;
27
+
28
+ // vectors
29
+ #define sz (x ) int ((x).size())
30
+ #define bg (x ) begin(x)
31
+ #define all (x ) bg(x), end(x)
32
+ #define rall (x ) x.rbegin(), x.rend()
33
+ #define sor (x ) sort(all(x));
34
+ #define sor_ (x ) sort(rall(x));
35
+ #define pb push_back
36
+ #define eb emplace_back
37
+ #define ft front ()
38
+ #define bk back ()
39
+ tcT > void remDup(vector<T> &v) { sort (all (v)), v.erase (unique (all (v)), end (v)); } // sort and remove duplicates
40
+ #define cpresent (container, element ) (find(all(container), element) != container.end()) // vector
41
+
42
+ // sets
43
+ #define present (container, element ) (container.find(element) != container.end()) // set/map
44
+ #define lb lower_bound
45
+ #define ub upper_bound
46
+ tcT > int lwb (V<T> &a, const T &b) { return int (lb (all (a), b) - bg (a)); }
47
+ tcT > int upb (V<T> &a, const T &b) { return int (ub (all (a), b) - bg (a)); }
48
+
49
+ // maps
50
+ typedef map<int , int > mii;
51
+ typedef map<str, int > msi;
52
+
53
+ // loops
54
+ #define FOR (i, a, b ) for (int i = (a); i < (b); ++i)
55
+ #define F0R (i, b ) FOR(i, 0 , b)
56
+ #define ROF (i, a, b ) for (int i = (b) - 1 ; i >= (a); --i)
57
+ #define R0F (i, b ) ROF(i, 0 , b)
58
+ #define rep (n ) FOR(_, 0 , n)
59
+ #define each (x, a ) for (auto &x : a)
60
+ #define tr (it, container ) \
61
+ for (typeof(container.begin()) it = container.begin(); it != container.end(); ++it)
62
+
63
+ // debug
64
+ #define debug (x ) cerr << #x << ' =' << (x) << endl;
65
+ #define debugp (x ) cerr << #x << " = {" << (x.first) << " , " << (x.second) << " }" << endl;
66
+ #define debug2 (x, y ) cerr << " {" << #x << " , " << #y << " } = {" << (x) << " , " << (y) << " }" << endl;
67
+ #define debugv (v ) \
68
+ { \
69
+ cerr << #v << " : " ; \
70
+ for (auto x : v) \
71
+ cerr << x << ' ' ; \
72
+ cerr << endl; \
73
+ }
74
+ #define wall cout << " ----------------------------------------\n " ;
75
+ #define kill (x ) \
76
+ { \
77
+ cout << x << endl; \
78
+ return ; \
79
+ }
80
+
81
+ // Etc...
82
+ #define PI 3.14159265358979323846
83
+ #define MOD 1000000007
84
+ const int inf = std::numeric_limits<int >::max();
85
+ const ll INF = std::numeric_limits<ll>::max();
86
+ const ld epsilon = 1 . / INF;
87
+ bool cmp (pii &a, pii &b) { return (a.second < b.second ); }
88
+
89
+ void solve ()
90
+ {
91
+ ll n;
92
+ cin >> n;
93
+ int ans = 0 ;
94
+ while (n != 1 )
95
+ {
96
+ if (n % 3 != 0 )
97
+ kill (-1 );
98
+ ans++;
99
+ if (n % 6 == 0 )
100
+ n /= 6 ;
101
+ else
102
+ n *= 2 ;
103
+ }
104
+ cout << ans << endl;
105
+ }
106
+
107
+ int main ()
108
+ {
109
+ ios_base::sync_with_stdio (false );
110
+ cin.tie (NULL ), cout.tie (NULL );
111
+
112
+ int t = 1 ;
113
+ cin >> t;
114
+ while (t--)
115
+ {
116
+ solve ();
117
+ }
118
+ return 0 ;
119
+ }
120
+
121
+ /* stuff you should look for
122
+ * int overflow, array bounds
123
+ * special cases (n=1?)
124
+ * do smth instead of nothing and stay organized
125
+ * WRITE STUFF DOWN
126
+ * DON'T GET STUCK ON ONE APPROACH
127
+ */
0 commit comments