text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int cntThree = 0, cntTwo = 0, val = 1; while (n % (val * 3LL) == 0) { ++cntThree; val *= 3; } while (n % (val * 2LL) == 0) { ++cntTwo; val *= 2; } if (val != n || (cntTwo > cntThree)) puts("-1"); else printf("%d\n", cntThree + (cntThree - cntTwo)); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; while (q--) { long long int n, k = 0, i; cin >> n; for (i = n; i >= 6;) { if (i % 6 == 0) { i = i / 6; k++; } else { i = i * 2; k++; if (i % 6 != 0) { break; } } } if (i == 1) { cout << k << endl; } else if (i == 3) { cout << k + 2 << endl; } else { cout << "-1" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { long long int casos; scanf("%lld", &casos); while (casos--) { long long int n; scanf("%lld", &n); long long int pot3 = 0; while (n % 3 == 0) { pot3++; n /= 3; } long long int pot2 = 0; while (n % 2 == 0) { pot2++; n /= 2; } long long int resp = 0; if (n != 1) { printf("-1\n"); continue; } long long int pot6 = min(pot3, pot2); resp += pot6; pot3 -= pot6, pot2 -= pot6; if (pot3 < pot2) { printf("-1\n"); continue; } resp += 2 * pot3; printf("%lld\n", resp); } return 0; }
#include <bits/stdc++.h> using namespace std; long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { cin >> n; int three = 0, two = 0; while (n % 2 == 0 || n % 3 == 0) { if (n % 2 == 0) { two++; n /= 2; } else { three++; n /= 3; } } if (n > 1 || three < two) cout << "-1" << endl; else cout << (2 * (three - two) + two) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, counter = 0; cin >> n; while (true) { if (n % 6 == 0) { n /= 6; counter++; } else if (n % 3 == 0) { n *= 2; counter++; } else { break; } } if (n == 1) { cout << counter << endl; } else { cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, i; cin >> t; for (i = 0; i < t; i++) { int n, j; int cnt = 0, cnt_1 = 0, ans = -1; cin >> n; while (n % 2 == 0) { cnt++; n = n / 2; } while (n % 3 == 0) { cnt_1++; n = n / 3; } if (n == 1 && cnt <= cnt_1) { ans = cnt_1 - cnt; ans = ans + cnt_1; } else { ans = -1; } cout << ans << endl; } }
#include <bits/stdc++.h> long long arr[1000009]; long long arr1[1000009]; const int MOD = 1e9 + 7; using namespace std; bool comp(string a, string b) { return a.size() < b.size(); } int main() { ios_base::sync_with_stdio(false); std::ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); long long t, n; cin >> t; while (t--) { cin >> n; long long count = 0; bool flag = true; while (n % 6 == 0 && n >= 1) { n /= 6; count++; } while (n % 6 != 0 && n >= 1) { if (n == 1) { cout << count << '\n'; flag = false; break; } n *= 2; count++; if (n == 1) { cout << count << '\n'; flag = false; break; } if (n % 6 == 0) { n /= 6; count++; } if (n == 1) { cout << count << '\n'; flag = false; break; } } if (flag == true) cout << -1 << '\n'; } }
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long q; cin >> q; while (q--) { long long n, a = 0, b = 0; cin >> n; while (n % 2 == 0) { n /= 2; a++; } while (n % 3 == 0) { n /= 3; b++; } if (n > 1 || a > b) cout << "-1\n"; else cout << 2 * b - a << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; void input_output() { ios_base::sync_with_stdio(false); cin.tie(NULL); } bool is_prime(int n) { if (n < 2) return false; int i; for (i = 2; i < (int)sqrt(n) + 1; i++) { if (n % i == 0) return false; } return true; } bool is_palindrome(string s) { int i; for (i = 0; i < s.size() / 2; i++) { if (s[i] != s[s.size() - i - 1]) return false; } return true; } int no_of_primes = 10; vector<bool> prime(no_of_primes + 1, true); vector<int> prime_nums; void sieve_of_erat() { prime[0] = false; prime[1] = false; int i, j; for (i = 2; i < (int)sqrt(no_of_primes) + 1; i++) { if (prime[i] == false) continue; j = 2 * i; while (j <= no_of_primes) { prime[j] = false; j += i; } } for (i = 0; i < no_of_primes + 1; i++) { if (prime[i] == true) prime_nums.push_back(i); } } vector<vector<int> > adj(1001); int bfs(int si, int n) { vector<bool> visited(n + 1, false); vector<int> dist(n + 1, -1); dist[si] = 0; queue<int> q; q.push(si); int i; while (!q.empty()) { int temp = q.front(); q.pop(); for (i = 0; i < adj[temp].size(); i++) { if (!visited[adj[temp][i]]) { q.push(adj[temp][i]); dist[adj[temp][i]] = dist[temp] + 1; visited[adj[temp][i]] = true; } } } return *max_element(dist.begin(), dist.end()); } void read_arr(vector<int> &v, int n) { int i; for (i = 0; i < n; i++) cin >> v[i]; } void solve() { long long n; cin >> n; int two = 0, three = 0; int i; long long k = n; while (n % 2 == 0) { n /= 2; two++; } n = k; while (n % 3 == 0) { n /= 3; three++; } n = k; if (pow(2, two) * pow(3, three) == n) { if (two <= three) cout << three + (three - two); else cout << -1; } else cout << -1; cout << '\n'; } int main() { input_output(); int t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 9; long long power(long long x, long long y) { if (y == 0) return 1; long long temp = power(x, y / 2); if (y % 2 == 1) return temp * temp * x; else return temp * temp; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; long long s1 = 0, s2 = 0; while (n % 2 == 0) { s1++; n /= 2; } while (n % 3 == 0) { s2++; n /= 3; } if (n == 1) { if (s1 <= s2) { long long ans = min(s1, s2); s1 -= ans; s2 -= ans; ans += s2 * 2; cout << ans << "\n"; } else { cout << "-1\n"; } } else cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using namespace chrono; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vvi = vector<vi>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> int sz(const T& a); template <typename T> int unq(vector<T>& a); template <typename T> T powi(T x, int i); template <typename T> T sqr(const T& x); template <typename T, typename U> auto maxx(const T& t, const U& u) -> typename common_type<T, U>::type; template <typename T, typename U> auto minn(const T& t, const U& u) -> typename common_type<T, U>::type; template <typename T, typename U> bool smin(T& t, const U& u); template <typename T, typename U> bool smax(T& t, const U& u); template <typename T, typename U, typename... V> auto maxx(const T& t, const U& u, const V&... v) -> typename common_type<T, U, V...>::type; template <typename T, typename U, typename... V> auto minn(const T& t, const U& u, const V&... v) -> typename common_type<T, U, V...>::type; template <typename T, typename U, typename... V> bool smin(T& t, const U& u, const V&... v); template <typename T, typename U, typename... V> bool smax(T& t, const U& u, const V&... v); template <typename T> inline string to_string(const vector<T>& x); template <typename T> inline string to_string(const vector<T>& x, int i); template <typename T> inline string to_string(const vector<T>& x, int i, int j); namespace InputReader { const int N = 1 << 16; char buffer[N]; char* iptr = buffer + N; char* endptr = buffer + N; bool hasMore = true; int bytesRead; inline bool reloadBuffer(); inline int gc(); inline bool read(char& x); inline bool read(char* x); inline bool read(string& x); inline bool readln(char* x); inline bool readln(string& x); template <typename T> inline bool readz(T& x); inline bool read(int& x); inline bool read(long long& x); template <typename T> inline bool read(vector<T>& a); template <typename T> inline bool reada(T* a, int n); template <typename T, typename... U> inline bool read(T& x, U&... y); inline int ni(); inline long long nl(); inline string ns(); inline vector<int> nvi(int n); inline vector<long long> nvl(int n); template <typename T> bool readv(vector<T>& v, int n); } // namespace InputReader using InputReader::ni; using InputReader::nl; using InputReader::ns; using InputReader::nvi; using InputReader::nvl; using InputReader::read; using InputReader::reada; using InputReader::readln; namespace OutputWriter { const int N = 1 << 16; char buffer[N]; char* iptr = buffer; char* const endptr = buffer + N; int bytesWritten = 0; void flushBuffer(); void pc(const int& c); inline bool print(const char& c); inline bool print(const char* a); inline bool print(char* a); inline bool print(const string& s); template <typename T> inline bool printz(T x); inline bool print(const int& x); inline bool print(const long long& x); inline bool print(const double& x); template <typename T, typename... U> inline bool print(const T& t, const U&... u); inline bool println(); template <typename T> inline bool println(const T& x); template <typename T, typename... U> inline bool println(const T& t, const U&... u); } // namespace OutputWriter using OutputWriter::print; using OutputWriter::println; bool solve(int testNumber); void solve(); int localTestCases = 1, testCount = 1; int MXITR = (int)1e7; const int inf = (int)1e9 + 7; const long long infl = (long long)4.6e18 + 7; const int md = (int)1e9 + 7; const bool multipleTestCases = 1; int steps(int n) { if (n == 1) return 0; if (n % 3 != 0) return -1; if (n & 1) { int s = steps(n / 3); if (s == -1) return -1; return 2 + s; } int s = steps(n / 6); if (s == -1) return -1; return 1 + s; } bool solve(int testNumber) { OutputWriter::println(steps(ni())); ; return true; } void solve() { if (false) InputReader::read(localTestCases); for (int i = 0; i < localTestCases; ++i) { if (multipleTestCases) InputReader::read(testCount); for (int testNumber = 1; testNumber <= testCount; ++testNumber) solve(testNumber); } OutputWriter::flushBuffer(); } int main() { if (false) { ignore = freopen("input.txt", "r", stdin); ignore = freopen("output.txt", "w", stdout); } else { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } auto t1 = high_resolution_clock::now(); solve(); auto t2 = high_resolution_clock::now(); duration<double> t = t2 - t1; if (false) printf("\n\nTime taken: %.5fs\n", t.count()); fclose(stdin); fclose(stdout); return 0; } template <typename T> int sz(const T& a) { return (int)a.size(); } template <typename T> int unq(vector<T>& a) { int n = a.size(); int m = unique(a.begin(), a.end()) - a.begin(); a.resize(m); return n - m; } template <typename T> T powi(T x, int i) { T r = 1; while (i) { if (i & 1) r *= x; x *= x; i /= 2; } return r; } template <typename T> T sqr(const T& x) { return x * x; } template <typename T, typename U> auto maxx(const T& t, const U& u) -> typename common_type<T, U>::type { return (t > u) ? t : u; } template <typename T, typename U> auto minn(const T& t, const U& u) -> typename common_type<T, U>::type { return (t < u) ? t : u; } template <typename T, typename U> bool smin(T& t, const U& u) { return (u < t) ? (t = u, true) : false; } template <typename T, typename U> bool smax(T& t, const U& u) { return (u > t) ? (t = u, true) : false; } template <typename T, typename U, typename... V> auto maxx(const T& t, const U& u, const V&... v) -> typename common_type<T, U, V...>::type { return maxx(maxx(t, u), v...); } template <typename T, typename U, typename... V> auto minn(const T& t, const U& u, const V&... v) -> typename common_type<T, U, V...>::type { return minn(minn(t, u), v...); } template <typename T, typename U, typename... V> bool smin(T& t, const U& u, const V&... v) { if (auto m = minn(u, v...); m < t) return (t = m, true); return false; } template <typename T, typename U, typename... V> bool smax(T& t, const U& u, const V&... v) { if (auto m = maxx(u, v...); m > t) return (t = m, true); return false; } template <typename T> inline string to_string(const vector<T>& x) { return to_string(x, 0, (int)x.size() - 1); } template <typename T> inline string to_string(const vector<T>& x, int i) { return to_string(x, i, (int)x.size() - 1); } template <typename T> inline string to_string(const vector<T>& x, int i, int j) { string s = to_string(x[i]); for (int k = i + 1; k <= j; ++k) s += ' ' + to_string(x[k]); return s; } inline bool InputReader::reloadBuffer() { bytesRead = fread(buffer, sizeof(buffer[0]), N, stdin); iptr = buffer; endptr = buffer + bytesRead; hasMore = (bytesRead != 0); return hasMore; } inline int InputReader::gc() { if (iptr == endptr) if (!reloadBuffer()) return EOF; return *iptr++; } inline bool InputReader::read(char& x) { int c = gc(); while (isspace(c) and c != EOF) c = gc(); if (c == EOF) { x = (char)0; if (false) assert(false); return false; } x = (char)c; return true; } inline bool InputReader::read(char* a) { int c = gc(); while (isspace(c) and c != EOF) c = gc(); if (c == EOF) { *a = '\0'; if (false) assert(false); return false; } while (!isspace(c) and c != EOF) { *a++ = (char)c; c = gc(); } *a = '\0'; return true; } inline bool InputReader::read(string& s) { static char t[(int)2e6 + 10]; if (!read(t)) return false; s.assign(t); return true; } inline bool InputReader::readln(char* a) { int c = gc(); while (isspace(c) and c != EOF) c = gc(); if (c == EOF) { *a = '\0'; if (false) assert(false); return false; } while ((c != '\n' and c != '\r' and c != '\f') and c != EOF) { *a++ = (char)c; c = gc(); } *a = '\0'; return true; } inline bool InputReader::readln(string& s) { static char t[(int)2e6 + 10]; if (!readln(t)) return false; s.assign(t); return true; } template <typename T> inline bool InputReader::readz(T& x) { int c = gc(); bool negative = false; x = 0; while (isspace(c) and c != EOF and c != '-') c = gc(); if (c == '-') { negative = true; c = gc(); } if (c == EOF) { if (false) assert(false); return false; } while (isdigit(c)) { x = x * 10 + (c - '0'); c = gc(); } if (negative) x = -x; return true; } inline bool InputReader::read(int& x) { return readz<int>(x); } inline bool InputReader::read(long long& x) { return readz<long long>(x); } template <typename T, typename... U> inline bool InputReader::read(T& x, U&... y) { bool b1 = read(x); bool b2 = read(y...); return b1 and b2; } template <typename T> inline bool InputReader::read(vector<T>& a) { bool b = true; for (auto& e : a) b &= read(e); return b; } inline int InputReader::ni() { int _; read(_); return _; } inline long long InputReader::nl() { long long _; read(_); return _; } inline string InputReader::ns() { string _; read(_); return _; } inline vector<int> InputReader::nvi(int n) { vector<int> v(n); for (int& e : v) read(e); return v; } inline vector<long long> InputReader::nvl(int n) { vector<long long> v(n); for (long long& e : v) read(e); return v; } template <typename T> inline bool InputReader::readv(vector<T>& v, int n) { v.resize(n); bool b = true; for (auto& e : v) b &= read(e); return b; } inline void OutputWriter::flushBuffer() { int r = fwrite(buffer, sizeof(buffer[0]), bytesWritten, stdout); if (false) assert(r == bytesWritten); iptr = buffer; bytesWritten = 0; } inline void OutputWriter::pc(const int& c) { *iptr = (char)c; ++bytesWritten; if (++iptr == endptr) flushBuffer(); } inline bool OutputWriter::print(const char& c) { pc(c); return true; } inline bool OutputWriter::print(char* a) { while (*a != '\0') pc(*a++); return true; } inline bool OutputWriter::print(const char* a) { while (*a != '\0') pc(*a++); return true; } inline bool OutputWriter::print(const string& s) { for (const char& c : s) pc(c); return true; } template <typename T> inline bool OutputWriter::printz(T x) { if (x < 0) { pc('-'); x = -x; } static int t[64]; if (x == 0) { pc('0'); return true; } int* ptr = t; int* const startptr = t; while (x) { *ptr++ = int(x % 10); x /= 10; } do { pc(*--ptr + '0'); } while (ptr != startptr); return true; } inline bool OutputWriter::print(const int& x) { return printz<int>(x); } inline bool OutputWriter::print(const long long& x) { return printz<long long>(x); } inline bool OutputWriter::print(const double& x) { static char a[64]; sprintf(a, "%.12f", x); return print(a); } template <typename T, typename... U> inline bool OutputWriter::print(const T& t, const U&... u) { print(t); print(' '); return print(u...); } inline bool OutputWriter::println() { pc('\n'); return true; } template <typename T> inline bool OutputWriter::println(const T& x) { print(x); return println(); } template <typename T, typename... U> inline bool OutputWriter::println(const T& t, const U&... u) { print(t); print(' '); return println(u...); }
#include <bits/stdc++.h> using namespace std; int main() { long t; long long n[20000]; cin >> t; for (long i = 0; i < t; i++) { cin >> n[i]; long long m = n[i]; long long dem3 = 0, dem2 = 0; while (m % 3 == 0) { m /= 3; dem3++; } while (m % 2 == 0) { m /= 2; dem2++; } if (m != 1 || dem3 < dem2) { n[i] = -1; continue; } else { n[i] = (dem3 - dem2) + dem3; continue; } } for (long i = 0; i < t; i++) { cout << n[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2; const long long int MOD = 1e9 + 7; void Solve() { long long int n; cin >> n; if (n == 1) { cout << "0" << "\n"; return; } if (n == 3) { cout << "2" << "\n"; return; } if (n == 6) { cout << "1" << "\n"; return; } if (n % 2 != 0 && n % 3 != 0) { cout << "-1" << "\n"; return; } long long int th = 0, tw = 0; while (n > 1 && n % 3 == 0) { th++; n /= 3; } while (n > 1 && n % 2 == 0) { tw++; n /= 2; } if ((n != 1) || (tw > th)) { cout << "-1" << "\n"; return; } if (th >= tw) { long long int ans = th - tw; ans += th; cout << ans << "\n"; return; } else { cout << "-1" << "\n"; return; } } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); ; int T; cin >> T; while (T--) { Solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline long long ceili(long long x, long long y) { return (x + y - 1) / y; } void solve() { long long n; cin >> n; long long cnt2 = 0, cnt3 = 0; while (n % 2 == 0) { n /= 2; ++cnt2; } while (n % 3 == 0) { n /= 3; ++cnt3; } if (n == 1 && cnt3 >= cnt2) cout << 2 * cnt3 - cnt2 << "\n"; else cout << -1 << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> a(2, 0); bool check(long long n) { a[0] = 0; a[1] = 0; while (1) { if (n % 2 == 0) { a[0]++; n /= 2; } else if (n % 3 == 0) { a[1]++; n = n / 3; } else break; } if (n == 1 && a[1] != 0 && a[0] <= a[1]) return true; else return false; } int main() { int t; cin >> t; while (t--) { long long n; cin >> n; if (n == 1) cout << 0 << endl; else if (check(n)) { cout << (a[1]) + (a[1] - a[0]) << endl; } else cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize(3) #pragma GCC optimize("Ofast") template <class T> inline void in(T &); template <class T> inline void out(const T &); using std::abs; using std::max; using std::min; using std::sort; using namespace std; int t, n, s1, s2; int main() { in(t); while (t--) { in(n); s1 = s2 = 0; while (n % 2 == 0) n /= 2, s1++; while (n % 3 == 0) n /= 3, s2++; if (n == 1 && s1 <= s2) out(2 * s2 - s1); else out(-1); putchar('\n'); } return 0; } template <class T> void in(T &Re) { T k = 0; char ch = getchar(); int flag = 1; while (!(ch >= '0' && ch <= '9')) { if (ch == '-') { flag = -1; } ch = getchar(); } while ((ch >= '0' && ch <= '9')) { k = (k << 1) + (k << 3) + ch - '0'; ch = getchar(); } Re = flag * k; } template <class T> void out(const T &Wr) { if (Wr < 0) { putchar('-'); out(-Wr); } else { if (Wr < 10) { putchar(Wr + '0'); } else { out(Wr / 10); putchar((Wr % 10) + '0'); } } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, m = 0; cin >> n; while (m < 1000000000000) { if (n % 6 == 0 && n >= 6) { n /= 6; m++; } if (n % 3 != 0 && n > 5) { cout << "-1" << endl; break; } if (n % 3 != 0 && n < 6 && n > 1) { cout << "-1" << endl; break; } if (n % 3 == 0 && n % 6 != 0) { n *= 2; m++; } if (n == 1) { cout << m << endl; break; } } } }
#include <bits/stdc++.h> using namespace std; void input_File() {} bool isPrime(long long n) { if (n <= 1) return false; for (long long i = 2; i < n; i++) if (n % i == 0) return false; return true; } long long sumofdigits(long long n) { long long c = 0; while (n > 0) { c++; n /= 10; } return c; } long long MaxSubArraySumReturn(long long a[], long long n) { long long sum = 0, best = 0; for (long long i = 0; i < n; i++) { sum = max(a[i], a[i] + sum); best = max(best, sum); } return best; } long long fact(long long n) { long long res = 1; for (long long i = 2; i <= n; i++) res = res * i; return res; } long long nCr(long long n, long long r) { return fact(n) / (fact(r) * fact(n - r)); } bool sortinrev(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first > b.first); } long long countDivisors(long long n) { long long cnt = 0; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return cnt; } long long setBitCount(long long n) { long long ans = 0; while (n) n &= n - 1, ans++; return ans; } long long power(long long a, long long b) { long long result = 1; while (b) { if (b & 1) { result *= a; b--; } else { a *= a; b >>= 1; } } return result; } vector<long long> nextLargerElementUsingStack(long long a[], long long n) { stack<long long> s; vector<long long> ans; ans.push_back(-1); s.push(a[n - 1]); for (long long i = n - 2; i >= 0; i--) { if (a[i] > s.top()) { while (!s.empty() and a[i] > s.top()) s.pop(); if (s.empty()) ans.push_back(-1); else ans.push_back(s.top()); s.push(a[i]); } else if (a[i] < s.top()) { ans.push_back(s.top()); s.push(a[i]); } } reverse(ans.begin(), ans.end()); return ans; } void solve() { long long n; cin >> n; if (n == 1) { cout << 0 << "\n"; return; } if (n == 3) { cout << 2 << "\n"; return; } if (n < 6 or n % 3) { cout << -1 << "\n"; return; } long long count = 0; while (n > 1) { if (n <= 1) break; if (n % 6 == 0) n /= 6, count++; else if ((n * 2 % 6) == 0) n *= 2, count++; else { cout << -1 << "\n"; return; } } cout << count << "\n"; } signed main() { input_File(); std::ios::sync_with_stdio(false); cin.tie(NULL); long long isTestCasePresent = 1; if (isTestCasePresent == 0) { long long t = 1; while (t--) { solve(); } } else { long long t; cin >> t; while (t--) { solve(); } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int32_t> dp(1, 0); void solve() { int64_t n; cin >> n; int64_t x3 = 0, x2 = 0; while (n % 3 == 0 && n != 1) { n /= 3; x3++; } while (n % 2 == 0 && n != 1) { n /= 2; x2++; } if (x3 >= x2 && n == 1) { cout << x3 + (x3 - x2) << '\n'; } else { cout << -1 << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t_; cin >> t_; while (t_--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n, a = 0, b = 0; cin >> n; if (n == 1) { cout << 0 << endl; } else { while (n % 3 == 0) { n /= 3; a++; } while (n % 2 == 0) { n /= 2; b++; } if (a >= b && n == 1) { cout << a + a - b << endl; ; } else { cout << -1 << endl; } } } return 0; }
#include <bits/stdc++.h> int main() { int t; std::cin >> t; while (t--) { long long n; std::cin >> n; int cnt = 0; long long m = n; std::map<long long, int> mp; mp[n] = 1; bool b = true; while (n > 1) { if (n % 6 == 0) n /= 6; else n *= 2; ++cnt; if (mp[n] == 1 || n > 2 * m) { b = false; break; } else mp[n] = 1; } if (b) std::cout << cnt << '\n'; else std::cout << "-1\n"; } }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int T, N; int main(int argc, char** argv) { scanf("%d", &T); for (int t = (0); t < (T); t++) { int ans = 0; scanf("%d", &N); while (N > 1 && !(N % 3)) { if (!(N % 6)) N /= 6; else N *= 2; ans++; } printf("%d\n", N == 1 ? ans : -1); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k1 = 0, k2 = 0, ans = 0; cin >> n; while (n % 3 == 0) { n /= 3; k1++; } while (n % 2 == 0) { n /= 2; k2++; } if (n != 1 || k2 > k1) ans = -1; else ans = 2 * k1 - k2; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; long long x = 0; bool flag = false; bool is_exist = true; cin >> n; while (n > 1) { if (!(n % 6)) { n /= 6; x++; flag = false; } else { if (flag) { is_exist = false; cout << -1 << '\n'; break; } n *= 2; x++; flag = true; } } if (is_exist) { cout << x << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long long t, i, n, c; cin >> t; while (t--) { c = 0; cin >> n; while (1) { if (n % 6 == 0) { n /= 6; c++; } else if (n % 3 == 0) { n *= 2; c++; } else break; } if (n == 1) cout << c << endl; else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { int t; cin >> t; while (t--) { ll n; cin >> n; if (n == 1) cout << "0" << endl; else { int ans = 0; while (n != 1 && (n % 6 == 0 || (n * 2) % 6 == 0)) { if (n % 6 == 0) { n = n / 6; ans++; } else { n = n * 2; ans++; } } if (n == 1) cout << ans << endl; else cout << "-1" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int w; cin >> w; while (w--) { long long int n; cin >> n; long long int ans; if (n == 1) { cout << "0" << endl; continue; } if (n % 3 != 0) { { cout << "-1" << endl; continue; } } long long int count = 0, count1 = 0; while (1) { if (n % 3 == 0) { if (n % 2 != 0) { n *= 2; count++; } n = n / 6; count1++; } else { if (n == 1) { cout << count + count1 << endl; break; } else { cout << "-1" << endl; break; } } } } return (0); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; long long cnt = 0; while (n != 1) { if (cnt > 1000) break; cnt++; if (n % 6 == 0) n /= 6ll; else n *= 2ll; } if (cnt > 1000) cout << -1 << endl; else cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first != b.first) return a.first > b.first; else { return a.second < b.second; } } void printV(vector<int> nums) { for (int i : nums) { printf("%d ", i); } printf("\n"); } int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool valid(int i, int j, int n, int m) { if (i >= 0 && i < n && j >= 0 && j < m) return true; else return false; } bool isPrime(int n) { if (n == 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } long long int kadane(vector<int> nums) { int n = nums.size(); long long int mx = 0; long long int curr = 0; for (int i = 0; i < n; i++) { curr += nums[i]; if (curr < 0) curr = 0; mx = max(mx, curr); } return mx; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int cnt = 0; bool flag = true; while (n != 1) { if (n % 6 == 0) n /= 6; else if ((n * 2) % 6 == 0) { n *= 2; } else { flag = false; break; } cnt++; } if (!flag) { cout << -1 << endl; } else { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { long long n; cin >> n; int j = 0; while (n != 1) { if (n % 6 == 0) { n /= 6; j++; } else if (n % 3 == 0) { n *= 2; j++; } else break; } cout << (n == 1 ? j : -1) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, i = 0, j = 0, l, x, y; cin >> n; x = n; y = n; while (x % 3 == 0 || x % 2 == 0) { if (x % 3 == 0) { x = x / 3; i++; } else { x = x / 2; j++; } } if (j > i || x != 1) cout << -1; else cout << i - j + i; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n == 1) { cout << 0 << endl; continue; } int cnt = 0, flag = 1; while (n != 1) { if (n % 3 != 0) { flag = 0; break; } else { if (n % 6 == 0) { cnt++; n /= 6; } else { cnt++; n = n * 2; } } } if (flag == 0) { cout << -1 << endl; } else { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long GCD(long long x, long long y) { if (!y) return x; return GCD(y, x % y); } long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); } void solve() { long long n, m = 1e9, i = 0, j = 0, k = 0, p, x, a = 1, y; cin >> n; while (n % 3 == 0) n /= 3, j++; while (n % 2 == 0) n /= 2, k++; if (n != 1 || k > j) { cout << "-1\n"; return; } cout << 2 * j - k << "\n"; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, cont, res; int cases; cin >> cases; while (cases--) { cont = 0; res = 0; cin >> n; while (n != 1) { if ((n * 2) % 6 != 0 && n % 6 != 0) { res = -1; n = 1; break; } if (n % 6 == 0) { n /= 6; cont++; } else { n *= 2; cont++; } } if (res != -1) { res = cont; } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return a < b ? a : b; } long long int min(long long int a, long long int b, long long int c) { a = min(a, b); a = min(a, c); return a; } long long int max(long long int a, long long int b) { return a > b ? a : b; } long long int max(long long int a, long long int b, long long int c) { a = max(a, b); a = max(a, c); return a; } long long int dsum(long long int n) { long long int ans = 0; while (n) { ans += (n % 10); n /= 10; } return ans; } long long int power(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) return a % m; long long int res = 1; a = a % m; while (b) { if (b & 1) { res = (res * a) % m; } a = ((a % m) * (a % m)) % m; b >>= 1; } return res; } long long int Ceil(long long int a, long long int b) { long long int res = a / b; if (a % b != 0) res++; return res; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) { os << t << " "; } os << '\n'; return os; } long long int dxx[] = {1, 1, 0, -1, -1, -1, 0, 1}; long long int dyy[] = {0, 1, 1, 1, 0, -1, -1, -1}; long long int dx[] = {1, 0, -1, 0}; long long int dy[] = {0, 1, 0, -1}; struct pll { long long int x, y; }; bool comp(pll a, pll b) { if (a.x == b.x) return a.y < b.y; else return a.x < b.x; } void solve(long long int the) { char ch; double aa, bb, cc, dd, xx; string s1, s2, s3, str; long long int i, j, k, a, b, c, d, n, m, l, r, x, y, z, low, high, mid, sum = 0, ans = 0, temp, t; cin >> n; if (n == 0) { cout << -1 << endl; return; } if (n == 1) { cout << 0 << endl; return; } if (n == 2) { cout << -1 << endl; return; } if (n == 3) { cout << 2 << endl; return; } if (n == 4 || n == 5) { cout << -1 << endl; return; } ans = 0; if (n & 1) { n = 2 * n; ans = 1; } while (n % 6 == 0) { n /= 6; ans++; if (n == 1) break; if (n & 1) { n = 2 * n; ans++; } if (n % 6 != 0) break; } if (n != 1) cout << -1 << endl; else cout << ans << endl; } int main() { long long int t = 1, c = 1; scanf("%lld", &t); while (t--) { solve(c); c++; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXM = 100010; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; int n, m, k; int tot, cnt, ans; int read() { int f = 1, s = 0; char ch = getchar(); while ('0' > ch || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { s = (s << 1) + (s << 3) + ((int)ch ^ 48); ch = getchar(); } return s * f; } int a[MAXN], b[MAXN]; string s; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int cnt1 = 0, cnt2 = 0; while (n % 2 == 0) { n /= 2; ++cnt1; } while (n % 3 == 0) { n /= 3; ++cnt2; } if (n > 1) { printf("-1\n"); continue; } if (cnt1 <= cnt2) printf("%d\n", cnt2 - cnt1 + cnt2); else printf("-1\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int cnt2 = 0, cnt3 = 0; while (n % 2 == 0) { n /= 2; ++cnt2; } while (n % 3 == 0) { n /= 3; ++cnt3; } if (n == 1 && cnt2 <= cnt3) { cout << 2 * cnt3 - cnt2 << endl; } else { cout << -1 << endl; } } }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, s, ans = 0; cin >> n; while (n % 6 == 0) { ans++; n /= 6; } while (n % 3 == 0) { ans += 2; n /= 3; } if (n == 1) cout << ans << "\n"; else cout << "-1" << "\n"; } int main() { long long t = 1; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, ji, pan, sum, he, x, y; scanf("%lld", &t); while (t--) { ji = pan = sum = he = 0; scanf("%lld", &n); if (n == 1) { printf("0\n"); pan = 1; } else if (n % 3 != 0) { printf("-1\n"); pan = 1; } else { x = n; while (x % 2 == 0) { sum++; x /= 2; } while (x % 3 == 0) { he++; x /= 3; } if (x != 1) { printf("-1\n"); pan = 1; } else { if (sum > he) { printf("-1\n"); pan = 1; } else { y = he - sum; ji = sum + y * 2; } } } if (pan == 0) { printf("%lld\n", ji); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; cin >> tests; while (tests--) { long long n; cin >> n; int cnt[2] = {0, 0}; long long temp = n; while (temp % 2 == 0) { temp = temp / 2; cnt[0]++; } while (temp % 3 == 0) { temp = temp / 3; cnt[1]++; } if ((temp > 1) || (cnt[0] > cnt[1])) { cout << "-1" << endl; } else { cout << (cnt[1] + (cnt[1] - cnt[0])) << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { long long int n; cin >> n; long long int counta = 0; if (n == 1) { cout << 0 << "\n"; continue; } long long int flag = 0; while (n != 1) { if (n % 6 == 0) n /= 6; else if (n % 3 == 0) { n = n * 2; } else { flag = 1; break; } counta++; } if (!flag) cout << counta << "\n"; else cout << -1 << "\n"; } return 0; }
#include <bits/stdc++.h> int main() { long long int t; scanf("%lld\n", &t); while (t--) { long long int n, a = 0; scanf("%lld\n", &n); while (1) { while (n % 6 == 0) { n = n / 6; a++; } if (n % 3 == 0) { n = n * 2; a++; } if (n == 1) { printf("%lld\n", a); break; } else if (n % 6 != 0) { printf("-1\n"); break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; bool is_prime(int n) { if (n == 1) { return false; } int i = 2; while (i * i <= n) { if (n % i == 0) { return false; } i += 1; } return true; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int temp = n; int a = 0, b = 0; if (n == 1) { cout << 0 << endl; continue; } while (temp % 3 == 0) { a++; temp /= 3; } if (a == 0) { cout << -1 << endl; continue; } while (temp % 2 == 0) { b++; temp /= 2; if (b > a) { break; } } if (temp == 1) { if (a >= b) { cout << a - b + a; } else { cout << -1; } } else { cout << -1; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int t = n; int cthree = 0; int ctwo = 0; while (t % 3 == 0) { cthree++; t /= 3; } while (t % 2 == 0) { ctwo++; t /= 2; } if (ctwo > cthree || t != 1) { cout << -1 << endl; } else { t = cthree - ctwo; t += cthree; cout << t << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, cn; cin >> t; for (int z = 0; z < t; z++) { cn = 0; cin >> n; while (n != 1) { if (n < 6 && n != 3) { cn = -1; break; } if (n % 6 == 0) { n = n / 6; cn++; } else { n = n * 2; cn++; } } cout << cn << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a; while (n--) { int count = 0; cin >> a; while (a % 6 == 0) { a = a / 6; count++; } while (a % 3 == 0) { a = a / 3; count = count + 2; } if (a == 1) { cout << count << endl; } else { cout << "-1" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long long n; cin >> n; if (n == 1) { cout << 0 << endl; continue; } long long ans = 0; while (n % 3 == 0) { if (n % 6 == 0) { ans++; n /= 6; continue; } n *= 2; ans++; } if (n != 1) { cout << -1 << endl; } else { cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long int n, val = 0; cin >> n; if (n == 1) cout << 0 << "\n"; else if (n % 3 != 0) cout << -1 << "\n"; else { long long int tem = n, count = 0, count1 = 0; while (tem % 3 == 0) { count++; tem /= 3; } if (n > pow(2, count) * pow(3, count)) cout << -1 << "\n"; else { if (tem % 2 == 1 && tem > 1) cout << -1 << "\n"; else { while (tem % 2 == 0) { count1++; tem /= 2; } if (tem % 2 == 1 && tem > 1) cout << -1 << " "; else cout << count - count1 + count << "\n"; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, n1, n, k, k1, j; cin >> t; vector<long long> ans, m; for (i = 1; i <= t; i++) { k = 0; k1 = 0; cin >> n; n1 = n; if (n == 1) { ans.push_back(0); continue; } while (n1 > 1) { for (j = 3; j >= 1; j--) if (n1 % j == 0) { if (j == 3) { k++; n1 = n1 / j; break; } if (j == 2) k1++; n1 = n1 / j; break; } if (k == 0 or j == 1) break; } if (k == 0 or k < k1 or j == 1) { ans.push_back(-1); continue; } if (k >= k1) ans.push_back(k + k - k1); } for (i = 0; i < ans.size(); i++) cout << ans[i] << endl; }
#include <bits/stdc++.h> using namespace std; long long mod(long long x) { x = x % 1000000007; if (x < 0) x += 1000000007; return x; } int gcd(int a, int b) { if (b > a) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } long long power(long long b, long long e) { if (e == 0) return 1; if (e == 1) return mod(b); long long res = power(b, e / 2); if (e % 2 == 0) return mod(res * res); return mod(res * mod(res * b)); } bool compare(vector<int>& a, vector<int>& b) { if (a[1] == b[1]) return a[0] > b[0]; return a[1] < b[1]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; if (n == 1) { cout << "0\n"; } else { int two = 0, three = 0; int f = 1; while (n > 1) { if (n % 2 == 0) { while (n % 2 == 0) { two++; n = n / 2; } } else if (n % 3 == 0) { while (n % 3 == 0) { three++; n = n / 3; } } else { f = 0; break; } } if (f == 0) { cout << "-1\n"; } else { if (two > three) { cout << "-1\n"; } else { long long ans = two + (three - two) * 2; cout << ans << "\n"; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long inf = 1e9; ll n, m, k; int main() { int t; cin >> t; while (t--) { cin >> n; int cnt = 0; map<ll, bool> ma; while (n != 1) { cnt++; if (ma[n]) { cnt = -1; break; } ma[n] = 1; if (n % 6 == 0) n /= 6; else n *= 2; } cout << cnt << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using lld = long double; const ll oo = 0x3f3f3f3f; const ll MOD = 1000000007; const ll N = 1e9 + 10; map<ll, ll> dis; inline void insert(const ll& x, const ll& p, queue<ll>& q) { if (x >= N) return; if (!dis.count(x)) { q.push(x); dis[x] = 1 + dis[p]; } } void bfs(ll src = 1) { queue<ll> q; q.push(src); dis[src] = 0; while (!q.empty()) { ll t = q.front(); q.pop(); if (t % 2 == 0) insert(t / 2, t, q); insert(t * 6, t, q); } } void solve() { ll n; cin >> n; if (!dis.count(n)) cout << "-1\n"; else cout << dis[n] << '\n'; return; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); bfs(); ll tc; cin >> tc; while (tc--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long x = 1, y = 1; int cnt1 = 0, cnt2 = 0; while (n % (x * 2) == 0) cnt1++, x *= 2; while (n % (y * 3) == 0) cnt2++, y *= 3; while (n > 1 && n % 2 == 0) n /= 2; while (n > 1 && n % 3 == 0) n /= 3; if (n > 1 || cnt1 > cnt2) cout << "-1\n"; else { cout << cnt2 + (cnt2 - cnt1) << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000005; long long a[10][N] = {}; void solve() { long long n, m = 0, i = 0, j = 0, l, r, k = 0, p = 1, x, y, b[200005]; cin >> n; while (n % 2 == 0) n /= 2, i++; while (n % 3 == 0) n /= 3, j++; if (i > j || n > 1) cout << "-1\n"; else { cout << 2 * j - i << "\n"; } } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int minmove(int n) { if (n == 1) return 0; if (n == 2) return -1; if (n % 6 == 0) { int p = minmove(n / 6); if (p != -1) return (1 + p); else return -1; } else if ((n * 2) % 6 == 0) { int q = minmove(n * 2); if (q != -1) { return (1 + q); } else return -1; } return -1; } int main() { int t; cin >> t; while (t) { int n; cin >> n; int ans = minmove(n); cout << ans << endl; t--; } }
#include <bits/stdc++.h> using namespace std; long long int modp(long long int a, long long int p, long long int n) { long long int d[100]; long long int i, j, k, l; if (n == 0) return 1; for (i = 0; n >= 1; i++) { d[i] = n % 2; n /= 2; } l = i; long long int e = 1; if (d[0] == 1) e *= (a % p); for (i = 1; i < l; i++) { a *= a; a = a % p; if (d[i] == 1) { e *= a; e = e % p; } } return e % p; } long long int modInverse(long long int n, long long int p) { return modp(n, p, p - 2); } bool sorter(pair<long long int, long long int>& a, pair<long long int, long long int>& b) { if (a.first != b.first) { return a.first > b.first; } return b.second > a.second; } long long int p1 = 1e9 + 7, p2 = 998244353; long long int l, r, mid, ans; long long int n, i, j, k, g, m; long long int x, y, n1, n2, h, z, c; long long int aa = 1; void solve() { cin >> n; x = 0; y = 0; while (n % 2 == 0) { x += 1; n /= 2; } while (n % 3 == 0) { y += 1; n /= 3; } if (n != 1 || x > y) { cout << "-1"; return; } ans = 2 * y - x; cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; cin >> t; long long int ans = 0; for (int i = 0; i < t; i++) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char s2[100]; int temp1 = 0, a = 0, c = 0, d = 0, b = 0; while (n >= 1) { if (n % 6 == 3) n *= 2, a++; s2[temp1++] = (char)(n % 6 + 48); n /= 6; if (s2[temp1 - 1] == '1') d++; else if (s2[temp1 - 1] == '0') 0; else b++; } if (s2[temp1 - 1] == '1' && d == 1 && b == 0) { cout << temp1 - 1 + a << endl; } else { cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long f; cin >> f; while (f--) { long long n; cin >> n; long long s1 = 0, s2 = 0; while (n % 2 == 0) { s1++; n /= 2; } while (n % 3 == 0) { s2++; n /= 3; } if (n == 1) { if (s1 <= s2) { long long ans = min(s1, s2); s1 -= ans; s2 -= ans; ans += s2 * 2; cout << ans << endl; } else { cout << "-1" << endl; } } else { cout << "-1" << endl; } } }
#include <bits/stdc++.h> using namespace std; void solve(int &m) { int count = 0; bool flag; again: if (m % 6 == 0) { m /= 6; count++; goto again; } else if (m % 3 == 0) { m /= 3; count += 2; goto again; } else if (m != 1) cout << -1 << "\n"; else cout << count << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int i = 0; int n[t]; while (i < t) { cin >> n[i]; if (n[i] == 1) cout << 0 << "\n"; else solve(n[i]); i++; } return 0; }
#include <bits/stdc++.h> using namespace std; using db = long double; using pll = pair<long long, long long>; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, i, x, j, y, z, k, n; long long tt; cin >> tt; for (long long _tt = 0; _tt < tt; _tt++) { cin >> n; z = 0; while (n != 1) { if (n % 6 == 0) n /= 6; else if ((n * 2) % 6 == 0) n *= 2; else { z = -1; break; } z++; } cout << z << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int num2 = {}, num3 = {}; while (n % 2 == 0) { n /= 2; num2++; } while (n % 3 == 0) { n /= 3; num3++; } if (n != 1 || num2 > num3) cout << "-1\n"; else cout << 2 * num3 - num2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; void run() { int N; cin >> N; int two = 0, three = 0; while (N % 2 == 0) { N /= 2; two++; } while (N % 3 == 0) { N /= 3; three++; } if (two > three || N != 1) { cout << -1 << '\n'; return; } cout << three + (three - two) << '\n'; } int main() { int t = 1; cin >> t; while (t--) { run(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n, c(0), d(0); scanf("%d", &n); while (n != 1) { ++c; if (d > 1) { c = -1; break; } else if (n % 6 == 0) { n /= 6; d = 0; } else { d++; n *= 2; } } printf("%d\n", c); ; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, k = 0, m = 0, h = 0; cin >> n; if (n % 2 != 0) { if (n == 1) { cout << 0 << endl; } if (n % 3 == 0) { while (1) { n = n / 3; k++; if (n % 3 != 0) { break; } } if (n == 1) { cout << k * 2 << endl; } else { cout << -1 << endl; } } else if (n > 1) { cout << -1 << endl; } } else { while (1) { if (n % 6 == 0) { n = n / 6; h++; } else if (n % 3 == 0 && n % 2 != 0) { while (1) { n = n / 3; m++; if (n % 3 != 0) { break; } } } else if (n == 1) { cout << m * 2 + h << endl; break; } else { cout << -1 << endl; break; } } } } }
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long sixs[15] = {1}, threes[22] = {1}; for (long long i = 1; i <= 14; i++) sixs[i] = sixs[i - 1] * 6; for (long long i = 1; i <= 21; i++) threes[i] = threes[i - 1] * 3; long long t; cin >> t; while (t--) { long long n; cin >> n; long long l = 0, r = 14, sres = 0, tres = 0; while (l <= r) { long long m = (l + r) / 2; if (n % sixs[m] == 0) sres = m, l = m + 1; else r = m - 1; } n /= sixs[sres]; l = 0, r = 21; while (l <= r) { long long m = (l + r) / 2; if (n % threes[m] == 0) tres = m, l = m + 1; else r = m - 1; } n /= threes[tres]; if (n != 1) cout << -1 << '\n'; else cout << sres + tres * 2 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; int n2 = 0, n3 = 0; while (N % 2 == 0) n2++, N /= 2; while (N % 3 == 0) n3++, N /= 3; int ans = -1; if (N == 1 && n2 <= n3) ans = (n3 - n2) + n3; cout << ans << endl; } int main() { int T; cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (long long p = 1; p <= t; p++) { long long angka; cin >> angka; if (angka == 1) { cout << "0\n"; continue; } long long langkah = 0; long long div3 = 0; long long div2 = 0; while (angka % 6 == 0) { angka = angka / 6; langkah++; } while (angka % 3 == 0) { angka = angka / 3; div3++; } while (angka % 2 == 0) { angka = angka / 2; div2++; } if (angka == 1) { if (div3 == 0 and div2 == 0) { cout << langkah << "\n"; continue; } } if (angka > 1) { cout << "-1\n"; } else { if (div3 == 0) { cout << "-1\n"; } else { if (div2 > div3) { cout << "-1\n"; } else { long long surplus = div3 - div2; langkah = langkah + surplus + div3; cout << langkah << "\n"; } } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int count = 0; while (n != 1) { if (n % 6 == 0) { n = n / 6; count++; } else { n = n * 2; if (n % 6 != 0) { count = -1; break; } count++; } } cout << count << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 200005; const long long MOD = 998244353; void solve() { long long n, k = 1, ans = 0; cin >> n; if (n == 1) { cout << "0\n"; return; } vector<long long> v; while (k <= 1e18) { v.push_back(k); k *= 6; } while (n <= 1e18) { long long p = lower_bound(v.begin(), v.end(), n) - v.begin(); if (v[p] == n) { ans += p; cout << ans << endl; return; } else ans++, n *= 2; } cout << "-1\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; i++) { long long a; cin >> a; if (a == 1) { cout << 0 << '\n'; continue; } int ans = 0; int res = 1; while (a > 1) { int cnt = 0; while (a % 6 != 0 && cnt < 4) { a *= 2; ans++; cnt++; } if (cnt > 3) { res = 0; cout << -1 << '\n'; break; } else { a /= 6; ans++; } } if (res == 1) { cout << ans << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long tw = 0, th = 0; long long temp = n; while (temp % 2 == 0) { tw++; temp /= 2; } while (temp % 3 == 0) { th++; temp /= 3; } if (temp != 1 || th < tw) { cout << "-1" << "\n"; } else { temp = th; temp += (th - tw); cout << temp << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int ans = 0; while (n % 3 == 0 || n % 6 == 0) { if (n % 6 == 0) { n /= 6; ans++; } else if (n % 3 == 0) { n /= 3; ans += 2; } } if (n != 1) { cout << -1 << endl; return; } cout << ans << endl; } int main() { int t = 1, i = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; if (n == 1) { cout << 0 << "\n"; return; } long long int count3 = 0; long long int count2 = 0; while (n % 3 == 0) { count3++; n /= 3; } while (n % 2 == 0) { count2++; n /= 2; } if (n != 1 || count3 < count2) { cout << "-1\n"; } else { cout << 2 * count3 - count2 << "\n"; } } int main() { int t = 1; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int two = 0; int three = 0; while (n % 2 == 0) { n /= 2; two++; } while (n % 3 == 0) { n /= 3; three++; } if (n != 1 || two > three) { cout << -1 << endl; continue; } else { int ans = three - two; ans += three; cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, cnt = 0; cin >> n; while (n > 1) { if (n % 6 == 0) { n = n / 6; cnt++; } else { n = n * 2; cnt++; if (n % 6 == 0) { n = n / 6; cnt++; } else { cout << "-1" << endl; break; } } } if (n == 1) { cout << cnt << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; template <typename T> void read(T &qq) { qq = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { qq = qq * 10 + ch - 48; ch = getchar(); } qq *= f; } int main() { int t; cin >> t; while (t--) { long long n; scanf("%lld", &n); int sum = 0; while (n >= 1) { if (n % 3 != 0) break; if (n % 6 == 0) { n /= 6; sum++; } else { n *= 2; sum++; } } if (n == 1) cout << sum << endl; else cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; inline int solve(long long n) { if (n == 1) return 0; if (n % 3 != 0) return -1; int res = 0; while (n != 1) { res++; if (n % 3 != 0) return -1; if (n % 6 == 0) n /= 6; else n <<= 1; } return res; } int main() { int t; cin >> t; while (t--) { long long n; cin >> n; cout << solve(n) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y, t, i, j, cnt2, k, cnt3; cin >> t; for (i = 0; i < t; i++) { cin >> x; k = 0; cnt2 = 0; cnt3 = 0; while ((x % 2) == 0) { x /= 2; cnt2++; } while ((x % 3) == 0) { x /= 3; cnt3++; } if (x > 1) { k = -1; } else if (x == 1) { if (cnt2 <= cnt3) { k = (cnt3 - cnt2) + cnt3; } else if (cnt3 < cnt2) { k = -1; } } cout << k << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { int m = 0, k = 0; int n; cin >> n; if (n == 1) cout << "0" << endl; else if (n % 3 != 0) cout << "-1" << endl; else { while (n != 1) { if (n % 3 == 0) { n = n / 3; m++; } else { if (n % 2 != 0) break; else { n = n / 2; k++; } } } if (n == 1 && m >= k) cout << 2 * m - k << endl; else if (n != 1 || m < k) cout << "-1" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int m) { if (y == 0) return 1; long long int p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } long long int nCr(long long int n, long long int r, long long int m) { if (r > n) return 0; long long int a = 1, b = 1, i; for (i = 0; i < r; i++) { a = (a * n) % m; --n; } while (r) { b = (b * r) % m; --r; } return (a * power(b, m - 2, m)) % m; } void solve() { long long int n; cin >> n; int t = 0, s = 0; while (n % 2 == 0) { n /= 2; t++; } while (n % 3 == 0) { n /= 3; s++; } if (n != 1) { cout << -1 << '\n'; return; } if (t == s) cout << t << '\n'; else if (t < s) cout << 2 * s - t << '\n'; else cout << -1 << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int two = 0, three = 0; while (n % 2 == 0) { n = n / 2; two++; } while (n % 3 == 0) { n = n / 3; three++; } if (n == 1 && two <= three) cout << (three - two) + three << "\n"; else { cout << "-1" << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; void solve_with_case(int cas) { cout << "Case " << ++cas << ": "; } void solve_without_case() { long long x, cnt = 0; cin >> x; while (x > 1) { if (x % 6 == 0) { x /= 6; cnt++; } if (x != 1 && x % 6 != 0) { x *= 2; cnt++; } } if (x < 1) cnt = -1; cout << cnt << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); ; int t, cas = 0; cin >> t; while (t--) { solve_without_case(); cas++; } }
#include <bits/stdc++.h> using namespace std; int pcalc(long long x, int a) { int m = 0; while (x % a == 0 && x >= a) { x /= a; m++; } return m; } void solve() { long long x; cin >> x; int n3 = pcalc(x, 3); int n2 = pcalc(x, 2); if ((n3 >= n2) && n3 != 0) { x *= pow(2, n3 - n2); x /= (long long)pow(6, n3); if (x == 1) { cout << 2 * n3 - n2 << '\n'; } else cout << -1 << '\n'; } else if (x == 1) cout << 0 << '\n'; else { cout << -1 << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return neg * x; } inline void print(int x) { if (x < 0) { putchar('-'); x = -x; } if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } int main() { int T = read(); while (T--) { int n = read(), ans = 0; while (n % 3 == 0) { if (n & 1) { ans += 2; n = 2 * n / 6; } else { ans++; n /= 6; } } printf("%d\n", n == 1 ? ans : -1); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t = 0, a, b, c = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> a; while (a > 1) { if (a % 6 == 0) { a = a / 6; } else { a = a * 2; } c += 1; } if (a == 1) { cout << c << endl; } else cout << "-1" << endl; c = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int pw3 = 0, pw2 = 0; while (n % 3 == 0) { pw3++; n = n / 3; } while (n % 2 == 0) { pw2++; n = n / 2; } if (n > 1) { puts("-1"); } else if (pw2 > pw3) { puts("-1"); } else { printf("%d\n", 2 * pw3 - pw2); } } }
#include <bits/stdc++.h> using namespace std; bool check(int a, int b) { if (b % a == 0) return true; return false; } void solve() { int n; cin >> n; bool can = true; int counter = 0; while (n > 1) { if (n % 6 == 0) { n /= 6; counter++; } else if ((n * 2) % 6 == 0) { n *= 2; counter++; } else { can = false; break; } } if (can) cout << counter << endl; else cout << -1 << endl; } int main() { int T; cin >> T; while (T--) solve(); }
#include <bits/stdc++.h> using namespace std; template <typename T> using min_queue = priority_queue<T, vector<T>, greater<T>>; const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T-- > 0) { long long N; cin >> N; int res = 0; while (1) { if (N == 1) break; if (N % 3) { res = -1; break; } if (N % 2) N *= 2; else N /= 6; res++; } cout << res << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int t; cin >> t; while (t--) { int n; cin >> n; int c2 = 0, c3 = 0; int nc = n; while (nc > 1 && nc % 2 == 0) { nc /= 2; c2++; } while (nc > 1 && nc % 3 == 0) { nc /= 3; c3++; } if (nc > 1 || c2 > c3) cout << -1 << endl; else cout << 2 * c3 - c2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); if (n == 1) { printf("0\n"); continue; } map<int, int> mps; int ans = 0; while (n > 1) { if (mps[n]) break; mps[n]++; if (n % 6 == 0) n /= 6; else n *= 2; ans++; } printf("%d\n", n == 1 ? ans : -1); } return 0; }
#include <bits/stdc++.h> using namespace std; void solve(int &m) { int count = 0; bool flag; again: if (m % 6 == 0) { m /= 6; count++; goto again; } else if (m % 3 == 0) { m /= 3; count += 2; goto again; } else if (m != 1) cout << -1 << endl; else cout << count << endl; return; } int main() { int t; cin >> t; int i = 0; int n[t]; while (i < t) { cin >> n[i]; if (n[i] == 1) cout << 0 << endl; else solve(n[i]); i++; } return 0; }
#include <bits/stdc++.h> template <typename T> constexpr int len(const T& container) { return container.size(); } using ll = long long; using namespace std; int INF = 1e9 + 5; pair<ll, ll> dirs[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; template <typename T, typename A> int argmax(std::vector<T, A> const& vec) { return static_cast<int>( std::distance(vec.begin(), max_element(vec.begin(), vec.end()))); } template <typename T, typename A> int argmin(std::vector<T, A> const& vec) { return static_cast<int>( std::distance(vec.begin(), min_element(vec.begin(), vec.end()))); } ll N = 0; unordered_map<ll, ll> memo; ll brute(ll n) { if (memo.find(n) != memo.end()) return memo[n]; if (n == 1) return 0; if (n > 6 * N) return INF; ll result = INF; if (n % 6 == 0) result = min(result, 1 + brute(n / 6)); result = min(result, 1 + brute(2 * n)); memo[n] = result; return result; } int main() { ll t; cin >> t; for (auto i = 0; i < t; ++i) { ll n; cin >> n; N = n; auto result = brute(n); if (result >= INF) result = -1; cout << result << "\n"; } }
#include <bits/stdc++.h> using namespace std; void fun() { long long hs[200001], a[100001], i, j, k, l = 0, t, s, x, n, y; cin >> n; if (n == 1) { cout << "0\n"; return; } while (1) { if (n % 6 == 0) { n /= 6; l++; } else if (n % 3 == 0) { n /= 3; l += 2; } else { cout << "-1\n"; return; } if (n == 1) break; } cout << l << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long number, n; cin >> n; while (n--) { fun(); } return 0; }
#include <bits/stdc++.h> using namespace std; void func(long long int N, long long int* cnt) { if (N == 1) return; if (N % 6 == 0) { (*cnt)++; func(N / 6, cnt); } else if (N % 2 == 0) { (*cnt) = -1; return; } else { if (N % 3 != 0) { (*cnt) = -1; return; } if (N % 3 == 0) { (*cnt) += 2; func(N / 3, cnt); } } } int main() { int T; cin >> T; while (T--) { long long int N; cin >> N; long long int cnt = 0; func(N, &cnt); cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; vector<long long> prime; bitset<1000030> vis; void seive() { vis.set(); vis[0] = false; vis[1] = false; vis[2] = true; prime.push_back(2); for (long long i = 3; i <= 1000030; i += 2) { if (vis[i] == 1) { prime.push_back(i); for (long long j = i * i; j <= 1000030; j += i) { vis[j] = 0; } } } } bool isPrime(long long n) { if (n < 2) return false; if (n < 4) return true; if (!(n & 1)) return false; if (n % 3 == 0) return false; long long lim = sqrt(n); for (long long i = 5; i <= lim; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } map<long long, long long> primeFact(long long n) { map<long long, long long> make_pair; while (n % 2 == 0) { make_pair[2]++; n = n / 2; } for (long long i = 3; i <= sqrt(n); i += 2) { while (n % i == 0) { make_pair[i]++; n = n / i; } } if (n > 2) { make_pair[n]++; } return make_pair; } long long binomialCoeff(long long n, long long k) { if (k > n) return 0; long long C[n + 1][k + 1]; long long i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = (C[i - 1][j - 1] % (1000000007) + C[i - 1][j] % (1000000007)) % (1000000007); } } return C[n][k]; } long long countDivisors(long long n) { long long cnt = 0; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else { cnt += 2; } } } return cnt; } void solve() { long long n; cin >> n; long long cn = 0; while (n != 1) { cn++; if (n % 3 != 0) { cout << -1 << "\n"; return; } if (n % 6 == 0) n /= 6; else n *= 2; } cout << cn << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; int cnt2 = 0, cnt3 = 0; while (n % 2 == 0) { n = n / 2; cnt2++; } while (n % 3 == 0) { n /= 3; cnt3++; } if (n == 1 && cnt3 >= cnt2) { cout << 2 * cnt3 - cnt2 << endl; } else { cout << "-1" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int t; cin >> t; while (t--) { int n; cin >> n; if (n == 1) { cout << 0 << endl; continue; } int two = 0; int three = 0; while (n % 2 == 0) { n /= 2; two++; } while (n % 3 == 0) { n /= 3; three++; } if (n != 1 || two > three) { cout << -1 << endl; continue; } cout << 2 * three - two << endl; } }
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void d_s_a() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { d_s_a(); long long t; cin >> t; while (t--) { long long n; long long counter = 0; cin >> n; bool x = true; while (1) { if (n == 1) break; if (n == 2 || n == 4 || n == 5 || n % 5 == 0) { x = false; break; } if (n % 6 == 0) { n = n / 6; counter++; } else { n = n * 2; counter++; } } if (!x) { cout << -1 << endl; } else cout << counter << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; if (n == 1) { cout << "0\n"; return 0; } if (n == 2) { cout << "-1\n"; return 0; } int t = 0; int sum = 0; while (t <= 2 && n != 1) { if (n % 2 == 0 && n % 3 == 0) { n /= 6; sum++; t = 0; } else { n *= 2; sum++; t++; } } if (t == 0) cout << sum << "\n"; else cout << "-1\n"; return 0; } int main() { int T; cin >> T; while (T--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { long long int n; cin >> n; long long int k = n; long long int c = 0; while (k > 1 && k <= n) { if (k <= n && k % 6 == 0) { k = k / 6; c++; } else { c++; if (k % 6 == 3) { n = k * 2; } k = k * 2; } } if (k > n) { cout << -1 << endl; } else cout << c << endl; } }