text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int t, i; cin >> t; while (t--) { long long int n, cnt = 0, flag = 0; cin >> n; while (n != 1) { if (n % 2 == 0 && n % 3 != 0) { flag = 1; break; } if (n % 6 == 0) n /= 6; else n *= 2; cnt++; } if (flag != 1) cout << cnt << endl; else cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long temp = n; long long count = 0; while (true) { if (temp == 1) { break; } if (temp == 2 || temp == 4) { break; } if (temp < 1) { break; } if (temp % 6 == 0) { temp = temp / 6; count++; } else { temp = temp * 2; count++; } } if (temp == 1) { cout << count << endl; } else { cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; for (cin >> t; t; t--) { int n; cin >> n; int move = 0; int m = 0; while (n != 1) { if (m == 2) { break; } if (n % 6 == 0) { n /= 6; move++; m = 0; } else { n *= 2; move++; m++; } } if (m == 2) { cout << -1 << endl; } else { cout << move << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; long long int n, count = 0; while (t) { cin >> n; while (n != 1) { if (n % 6 == 0) { count++; n /= 6; } else if (n % 3 == 0 && n % 6 != 0) { count += 2; n /= 3; } else { cout << -1 << endl; break; } } if (n == 1) { cout << count << endl; } count = 0; t--; } }
#include <bits/stdc++.h> using namespace std; long long int solve() { long long int n; cin >> n; long long int cnt2 = 0; long long int cnt3 = 0; while (n % 2 == 0) { n /= 2; cnt2++; } while (n % 3 == 0) { n /= 3; cnt3++; } if (n > 1) return -1; if (cnt2 > cnt3) return -1; return cnt3 - cnt2 + cnt3; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) cout << solve() << endl; }
#include <bits/stdc++.h> using namespace std; int n, t; int main() { cin >> t; for (int i = 1; i <= t; ++i) { cin >> n; int d2 = 0, d3 = 0; while (n % 2 == 0) { n /= 2; d2++; } while (n % 3 == 0) { n /= 3; d3++; } if (n != 1 || d3 < d2) { cout << -1 << '\n'; continue; } cout << d3 + d3 - d2 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, s; cin >> t; while (t--) { cin >> n; s = 0; while (n != 1) { if (n % 6 == 0) { s++; n = n / 6; } else { if (n % 6 == 3) { s++; n = n * 2; } else { s = -1; break; } } } cout << s << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long t = n; while (t % 2 == 0) { t /= 2; } while (t % 3 == 0) { t /= 3; } if (t != 1) { cout << -1 << "\n"; return; } t = n; long long a = 0; long long b = 0; while (t % 2 == 0) { a++; t /= 2; } t = n; while (t % 3 == 0) { b++; t /= 3; } if (a > b) cout << -1; else cout << (b - a) + b; cout << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long test; cin >> test; while (test--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { long long n, a[200009], c = 0, ct = 0; string s; cin >> n; while (n % 2 == 0) { n /= 2; ct++; } while (n % 3 == 0) { n /= 3; c++; } if (c < ct || n != 1) cout << "-1" << endl; else cout << c + (c - ct) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, z, x, s; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long s = 0; set<long long> ss; ss.clear(); int ff = 0; while (n != 1) { ss.insert(n); if (n % 6 == 0) n /= 6, s++; else n *= 2, s++; if (ss.count(n) == 1 || n == 0) { ff = 1; break; } } if (ff == 0) cout << s << "\n"; else cout << -1 << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; int count = 0; while (n % 6 == 0) { n = n / 6; count++; } while (n % 6 == 0 || n % 3 == 0) { if (n % 6 == 0) { n = n / 6; count++; continue; } count++; n = n * 2; } if (n == 1) { cout << count << endl; } else cout << "-1" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { long long n; cin >> n; long long res = 0; long long count = 0; while (1) { if (n == 1) { cout << res << "\n"; break; } if (n % 6 == 0) { count = 0; n = n / 6; } else { n = n * 2; count++; } if (count == 2) { cout << -1 << "\n"; break; } res++; } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int count_3 = 0, count_6 = 0; while (n % 3 == 0 || n % 6 == 0) { if (n % 6 == 0) { n = n / 6; count_6++; } else { n = n / 3; count_3++; } } if (n == 1) { cout << count_6 + 2 * count_3 << endl; } else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, k, c = 0, t; cin >> t; while (t--) { cin >> n; while (n > 1) { if (n % 6 == 0) { n = n / 6; c++; } else { n = n * 2; c++; } } if (n == 1) cout << c << endl; else cout << "-1" << endl; c = 0; } }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long cnt = 0; while (n != 1) { if (n % 6 == 2 || n % 6 == 5) { cnt = -1; break; } else if (n % 6 == 0) { n /= 6; cnt++; } else { n *= 2; cnt++; } } cout << cnt << endl; } int main() { long long int t; cin >> t; for (long long int tc = 1; tc <= t; tc++) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } int n; long long int solve() { long long int res = 0; int pow2 = 0; int pow3 = 0; int n2 = n; int n2a = 1; while (n2 % 2 == 0) { n2 /= 2; pow2++; n2a *= 2; } int n3b = 1; int n3 = n; while (n3 % 3 == 0) { n3 /= 3; pow3++; n3b *= 3; } if (n2a * n3b != n) { return -1; } if (pow2 > pow3) { return -1; } res = pow3; res += pow3 - pow2; return res; } int main() { int T; cin >> T; for (int t = 0; t < T; t += 1) { cin >> n; cout << solve() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool trash(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } void solve() { long long int a, b, c, n, nn, m, t, k, r, x, y, z, o, l, dd = 1000000, rr, i, sl, tl, d, mid, val, j, lo, h, e, tmp, cn, cf, flag; long long int ans = 0, sum = 0, two = 0, three = 0; cin >> x; if (x == 1) { cout << 0 << "\n"; } else if (x == 3) { cout << 2 << "\n"; } else if (x < 6) { cout << -1 << "\n"; } else { while (x % 2 == 0) { x = x / 2; two++; } while (x % 3 == 0) { x /= 3; three++; } if (x != 1 or three < two) cout << -1 << "\n"; else cout << (2 * three) - two << "\n"; } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); long long int t = 1; cin >> t; while (t--) { solve(); } 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 == 1) { cout << k << endl; } else if (i == 3) { cout << k + 2 << endl; } else { cout << "-1" << endl; } } }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int c = 0; if (n == 1) { cout << 0 << endl; return; } while (n != 1) { if (n % 3 != 0) { cout << -1 << endl; return; } if (n % 6 == 0) { n = n / 6; } else { n = n * 2; } c++; } cout << c << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int ans = 0; while (true) { if (n == 1) { cout << ans << endl; return; } if (n % 6 == 0) { n /= 6; } else if (n % 3 == 0) { n *= 2; } else { cout << -1 << endl; return; } ans++; } } 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; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int modInverse(long long int A, long long int M) { return power(A, M - 2, M); } void solve() { long long int n; cin >> n; int ans = 0; if (n == 1) { cout << 0 << "\n"; return; } while (n != 1) { if (n % 3 != 0) { cout << -1 << "\n"; return; } if (n % 6 == 0) n /= 6; else n *= 2; ans++; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; for (int i = 1; i <= t; i++) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { int n; cin >> n; if (n == 1) { cout << 0 << endl; continue; } int three = 0; while (n % 3 == 0) { n = n / 3; three++; continue; } int two = 0; while (n % 2 == 0) { n = n / 2; two++; } if (n != 1) { cout << -1 << endl; continue; } if (two > three) { cout << -1 << endl; continue; } cout << three + three - two << endl; } }
#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; int c2 = 0, c3 = 0; while (n % 2 == 0) { c2++; n /= 2; } while (n % 3 == 0) { c3++; n /= 3; } if (n == 1) { if (c3 >= c2) cout << (c3 * 2 - c2) << endl; else { cout << "-1\n"; } } else { cout << "-1" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 5; const int INF = 0x3f3f3f3f; const long long LINF = (long long)2e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long a = 0, b = 0, p = n, c = 0; while (p > 1) { if (p % 2 == 0) { a++; p /= 2; } else if (p % 3 == 0) { b++; p /= 3; } else { c++; break; } } if (c) cout << -1 << "\n"; else if (b < a) cout << -1 << "\n"; else cout << 2 * b - a << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const int inf = 0x3f3f3f; const int maxn = 3e5 + 5; const int mod = 998244353; int k[maxn]; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, x, y; cin >> n; int ans = 0; ; 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'; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int cnt = 0; while (n % 6 == 0) { n = n / 6; cnt++; } while (n % 3 == 0) { n = n / 3; cnt += 2; } if (n == 1) cout << cnt << endl; else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, t; cin >> t; while (t--) { cin >> n; int sum = 0, cnt = 0; while (n != 1 && cnt != -1) { if (n % 6 == 0) { n = n / 6; cnt++; } else if (n % 3 == 0) { n = n / 3; cnt = cnt + 2; } else if (n != 1) { cnt = -1; } } cout << cnt << endl; } }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long c1 = 0, c2 = 0; while (n % 3 == 0) { n /= 3; c1++; } while (n % 2 == 0) { n /= 2; c2++; } if (c1 < c2 || n != 1) { cout << "-1\n"; } else cout << abs(c1 - c2) + c1 << "\n"; } }
#include <bits/stdc++.h> using namespace std; void allprime(int n, bool prime[]) { for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } void bfs(vector<int> adj[], int src, bool vis[], int level[]) { queue<pair<int, int> > q; q.push(make_pair(src, 0)); vis[src] = true; level[src] = 0; while (!q.empty()) { pair<int, int> vpair = q.front(); q.pop(); int v = vpair.first; int lvl = vpair.second; for (int i = 0; i < adj[v].size(); i++) { int next = adj[v][i]; if (!vis[next]) { q.push(make_pair(next, lvl + 1)); vis[next] = true; level[next] = lvl + 1; } } } } void dfs(vector<int> adj[], int src, bool vis[]) { vis[src] = true; for (int i = 0; i < adj[src].size(); i++) { int next = adj[src][i]; if (!vis[next]) { dfs(adj, next, vis); } } } void solve() { int n; cin >> n; int pow2 = 0, pow3 = 0; while (n % 2 == 0) { n /= 2; pow2++; } while (n % 3 == 0) { n /= 3; pow3++; } if (n != 1) cout << -1 << endl; else if (pow3 < pow2) cout << -1 << endl; else cout << 2 * pow3 - pow2 << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, k, n; cin >> t; while (t--) { long long int ans = 0, flag = 1; cin >> n; while (n != 1) { if (n % 6 == 0) { n = n / 6; ans++; } else if (n % 3 == 0) { n = n * 2; ans++; } else break; } if (n != 1) { cout << "-1" << endl; continue; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; int a[2] = {0}; for (int i = 2; i <= 3;) { if (n % i == 0) { a[i - 2]++; n /= i; i--; } i++; } if (n != 1) { cout << -1 << endl; } else if (a[1] < a[0]) { cout << -1 << endl; } else { cout << (2 * a[1] - a[0]) << endl; } } }
#include <bits/stdc++.h> using namespace std; long long zero = 0; int main() { long long t; cin >> t; while (t) { long long n; cin >> n; long long ans = 0; long long temp = n; while (temp != 1) { if (temp % 6 == 0) { temp = temp / 6; ans++; } else if (temp % 3 == 0) { temp = temp / 3; ans = ans + 2; } else { break; } } if (temp != 1) { ans = -1; } cout << ans << endl; t--; } }
#include <bits/stdc++.h> using namespace std; int main() { int t, n, sum = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> n; if (n < 6 && n != 1 && n % 3 != 0) { cout << "-1" << "\n"; continue; } if (n == 1) { cout << sum << "\n"; continue; } while (true) { if (n % 6 == 0) { n /= 6; sum++; } else { n *= 2; sum++; } if (n == 1) { cout << sum << "\n"; break; } if (n < 6 && n != 1 && n % 3 != 0) { cout << "-1" << "\n"; break; } } sum = 0; } }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, k = 0, m; cin >> n; while (n % 6 == 0) { n /= 6; k++; } while (n % 3 == 0) { n /= 3; k += 2; } if (n != 1) cout << "-1" << endl; else cout << k << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long t; cin >> t; while (t--) { long long n; cin >> n; long long ans = 0; while (!(n % 3)) { if (n % 2) { ans += 2; n /= 3; } else { ans += 1; n /= 6; } } if (!(n - 1)) { cout << ans << '\n'; } else { cout << "-1\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> ans; void solve(long long n) { long long step = 0; while (n != 1) { if (n % 2 == 0) { if (n % 6 != 0) { ans.push_back(-1); return; } n /= 6; if (n == 0) { ans.push_back(-1); return; } } else { n *= 2; if (n % 6 != 0) { ans.push_back(-1); return; } } ++step; } ans.push_back(step); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long n; cin >> n; solve(n); } for (int i = (0); i < (ans.size()); ++i) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int Tc; cin >> Tc; while (Tc--) { long long int n, i = 0, flag = 0; cin >> n; if (n > 6) { while (true) { if (n % 6 == 0) { n /= 6; i++; } else if (n % 3 == 0) { n *= 2; i++; } else if (n == 1) { break; } else { flag = 1; break; } } if (flag == 1 || n != 1) cout << -1 << endl; else cout << i << endl; } else { if (n == 3) cout << 2 << endl; else if (n == 6) cout << 1 << endl; else if (n == 1) cout << 0 << endl; else cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; void deCode() { long long n, c = 0; cin >> n; if (n == 1) { cout << 0 << '\n'; return; } while (1) { while (n % 6 == 0) { n = n / 6; c++; } if (n == 1) { cout << c << '\n'; return; } if (n % 3 != 0) { cout << -1 << '\n'; return; } else { c++; n = n * 2; } } } int main() { int t; scanf("%d", &t); while (t--) deCode(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, count = 0; cin >> n; if (n == 1) cout << "0" << endl; else { while (n != 1) { if (n % 6 == 0) { n /= 6; count++; } else if (n % 3 == 0) { n /= 3; count += 2; } else { count = -1; break; } } cout << count << endl; } } }
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> mp, mk; set<long long int> s1, s2; vector<long long int> v, w; long long int a[2000006], b[2000006]; string s = "", p = "", q = ""; char ch; long long int m, n, c, d, i, j, k, l, r, x, t, y, u, e, f, g, h, mn, mx; int main() { cin >> t; while (t--) { cin >> n; while (n % 2 == 0) { n /= 2; c++; } while (n % 3 == 0) { n /= 3; d++; } if (n == 1 && c <= d) e = 2 * d - c; else e = -1; cout << e << endl; c = 0; d = 0; } }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void debug(vector<T> v) { cout << "\ndebug(vector)\n"; long long i; for (i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } inline bool prime(int n) { int i; for (i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long count = 0; while (n / 10 != 0) { if (n % 6 == 0) { n = n / 6; count++; } else { n = n * 2; count++; } } if (n == 3) { count = count + 2; cout << count << endl; } else if (n == 9) { count = count + 4; cout << count << endl; } else if (n == 1) { count = count; cout << count << endl; } else if (n == 6) { count = count + 1; cout << count << endl; } else cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int t = 0; cin >> t; while (t--) { long long int n = 0; long long int s = 0; bool flag = false; cin >> n; while (n != 1) { if (n % 6 == 0) { n = n / 6; s++; } else { if (n > 1000000000) { cout << -1 << endl; flag = true; break; } n = n * 2; s++; } } if (flag != true) { cout << s << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t, i; cin >> t; for (i = 0; i < t; i++) { long long n, c = 0, f = 0; cin >> n; while (n != 1) { if (n % 6 == 0) { n = n / 6; c++; } else if (n % 3 == 0) { n = n * 2; c++; } else { f = 1; break; } } if (f == 0) cout << c << endl; else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t, x, y, n; scanf("%d", &t); while (t--) { scanf("%d", &n); int cnt = 0, f = 0; while (n >= 6) { if (n % 3 == 0 && n % 6 != 0) { cnt++; n = n * 2; } else if (n % 6 == 0) { cnt++; n = n / 6; } else { f = 1; break; } } if (n == 3) printf("%d\n", cnt + 2); else if (n == 6) printf("%d\n", cnt + 1); else if (n == 1) printf("%d \n", cnt); else printf("-1\n"); } }
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long ans = 0; if (n == 1) { cout << "0" << endl; } else if (n % 3 == 0) { while (n > 1 && n > 2) { if (n % 6 == 0) { n = n / 6; } else { n = n * 2; } ans++; } if (n == 1) { cout << ans << endl; } else { cout << "-1" << endl; } } else { cout << "-1" << endl; } } int main() { long long t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf(" %d", &n); int twos = 0, threes = 0; while (n % 2 == 0) { n /= 2; ++twos; } while (n % 3 == 0) { n /= 3; ++threes; } if (n > 1 || twos > threes) { printf("-1\n"); return; } int res = threes - twos + threes; printf("%d\n", res); } int main() { int t; scanf(" %d", &t); while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int t; int main() { cin >> t; while (t--) { long long n; cin >> n; if (n == 1) { cout << "0\n"; continue; } int cnt3 = 0; int cnt2 = 0; while (n % 3 == 0) { cnt3++; n /= 3; } while (n % 2 == 0) { cnt2++; n >>= 1; } if (n > 1 || cnt3 < cnt2) { cout << "-1\n"; continue; } int dif = cnt3 - cnt2; cout << dif * 2 + cnt2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long counter = 0; while (n != 1) { if (n % 2 != 0) { n = n * 2; counter++; } else { if (n % 6 != 0) { counter = -1; break; } n = n / 6; counter++; } } cout << counter << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n == 1) { return false; } long long flag = 1; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { flag = 0; break; } } if (flag == 1) { return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; if (n == 1) { cout << 0 << "\n"; continue; } long long tc = 0; while (n % 3 == 0) { n /= 3; tc++; } if (tc == 0) { cout << -1 << "\n"; } else { long long twc = 0; while (n % 2 == 0) { n /= 2; twc++; } if (n != 1 || twc > tc) { cout << "-1\n"; } else { long long sum = 0; sum += tc - twc; sum += tc; cout << sum << "\n"; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, cont = 0; cin >> n; unordered_map<int, int> mp; while (n != 1) { if (n % 6 == 0) n /= 6; else n *= 2; if (mp[n] == 1) { cont = -1; goto sw; } mp[n]++, cont++; } sw:; cout << cont << "\n"; } }
#include <bits/stdc++.h> using namespace std; int solve1(int n, int ans) {} void solve() { long long n; cin >> n; long long countOfThree = 0, countOfTwo = 0; while (n % 2 == 0) { countOfTwo++; n = n / 2; } while (n % 3 == 0) { countOfThree++; n = n / 3; } if (n != 1) cout << -1; else { long long diff = countOfThree - countOfTwo; if (diff < 0) cout << -1; else if (diff == 0) cout << countOfThree; else { cout << diff + countOfThree; } } } int main() { int t; cin >> t; while (t--) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll t; cin >> t; while (t--) { ll cnt3, cnt2; cnt2 = cnt3 = 0; ll n; cin >> n; while (n % 2 == 0) { n = n / 2; cnt2++; } while (n % 3 == 0) { n = n / 3; cnt3++; } if (n != 1 || cnt2 > cnt3) cout << -1 << "\n"; else { ll ans = cnt2 + (cnt3 - cnt2) * 2; cout << ans << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; int count = 0, sum = 0; while (n % 2 == 0) { count++; n = n / 2; } while (n % 3 == 0) { sum++; n = n / 3; } if (n == 1 && sum >= count) { cout << 2 * sum - count; } else { cout << -1; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long count = 0; int flag = 1; while (n != 1) { if (n % 3 != 0) { flag = 0; break; } if (n % 6 == 0) { n = n / 6; count++; continue; } n = n * 2; count++; } if (flag) cout << count << "\n"; else cout << -1 << "\n"; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e7; void solve() { long long n, two = 0, thre = 0; cin >> n; if (n == 1) cout << 0; else { while (n % 2 == 0 || n % 3 == 0) { while (n % 2 == 0) { two++; n = n / 2; } while (n % 3 == 0) { thre++; n = n / 3; } } if (n != 1 || two > thre) cout << -1; else { long long diff = thre - two; cout << thre + diff; } } cout << endl; } int main() { long long t = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; long long y, n, i, p, d, putere2, putere3, t; bool ok; int main() { cin >> t; for (i = 1; i <= t; i++) { cin >> n; putere2 = 0; putere3 = 0; d = 2; ok = true; while (n % 2 == 0) { n /= 2; putere2++; } while (n % 3 == 0) { n /= 3; putere3++; } if (n > 1 || putere2 > putere3) { cout << -1 << '\n'; continue; } if (putere2 <= putere3) cout << putere3 - putere2 + putere3 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int tc = 0, thc = 0; while (n % 2 == 0) { tc++; n /= 2; } while (n % 3 == 0) { thc++; n /= 3; } if (n == 1 and thc >= tc) cout << (2 * thc - tc) << "\n"; else cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, c = 0; cin >> n; while (n >= 1) { if (n % 6 == 0) { n = n / 6; c++; } else if (n % 3 == 0) { n = n * 2; c++; } else if (n == 1) { cout << c << "\n"; break; } else { cout << "-1" << "\n"; break; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, count = 0; cin >> n; while (n > 0) { if (n % 6 == 0) { n = n / 6; count++; } else if (n % 3 == 0) { n = n * 2; count++; } else { break; } } if (n == 1) { cout << count << endl; } else { cout << "-1" << endl; } } }
#include <bits/stdc++.h> using namespace std; int ans(int n) { if (n == 1) return 0; int tp = 0, twop = 0; while (n % 3 == 0) { n = n / 3; tp++; } while (n % 2 == 0) { n = n / 2; twop++; } if (twop > tp) return -1; if (n == 1) return 2 * tp - twop; return -1; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << ans(n) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const int N = 105; int a[55], b[55]; int main() { int T; cin >> T; while (T--) { long long n, res = 0; cin >> n; while (n > 1) { if (n % 3 != 0) { res = -1; break; } if (n % 6 == 0) { n /= 6; } else { n *= 2; } res++; } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x = 0, c = 0; cin >> n; while (n != 1) { if (x == 3) { cout << "-1" << endl; break; } if (n % 6 == 0) { n /= 6; c++; x = 0; } else { n *= 2; c++; x++; } } if (n == 1) { cout << c << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long ans = -1; long long p2 = 0, p3 = 0; while (n % 2 == 0) { n /= 2; p2++; } while (n % 3 == 0) { n /= 3; p3++; } if (n == 1 && p2 <= p3) { ans = 2 * p3 - p2; } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int ans = 1; while (b) { if (b & 1LL) ans = (ans * a) % 998244353; a = (a * a) % 998244353; b = b >> 1LL; } return ans; } int t; int n; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; for (int a0 = 0; a0 < t; a0++) { cin >> n; int s2 = 0; int s3 = 0; while (n % 2 == 0) { n /= 2; s2++; } while (n % 3 == 0) { n /= 3; s3++; } if (n != 1 || s2 > s3) { cout << "-1\n"; continue; } cout << 2 * (s3 - s2) + s2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const unsigned long long mod = (unsigned long long)1e9; long long n, k, x, t, ans = 0, l, m, d, mx = 0, mi = 1000000; string a, b; double dans = 0, f; long long s, c; unsigned long long arr[2233]; unsigned long long pre[2233]; unsigned long long vr = 1, vc = 1, hr = 1, hc = 2; char mat[50][50]; void solve() { cin >> n; int i = 0; while (n > 1) { i++; if (n % 6 == 0) { n /= 6; continue; } if (n % 3 != 0) { cout << "-1\n"; return; } n *= 2; } cout << i << "\n"; } int main(int argc, char *argv[]) { cin >> t; for (unsigned long long i = 0; i < t; i++) solve(); }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long two = 0, three = 0; if (n == 1) { cout << 0 << '\n'; continue; } while (n) { if (n % 2 == 0) { two++; n /= 2; } else { break; } } while (n && n != 1) { if (n % 3 == 0) { three++; n /= 3; } else { break; } } if (n != 1) { cout << -1 << '\n'; } else { if (two > three) { cout << -1 << '\n'; } else { long long ans = three - two; ans += three; cout << ans << '\n'; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; if (n == 1) cout << "0" << endl; else if (n == 2) cout << "-1" << endl; else if (n * 2 <= 6) { if (n * 2 % 6 == 0) cout << "2" << endl; else cout << "-1" << endl; } else { int cnt = 0; while (n > 1) { if (n % 6 == 0) { cnt++; n = n / 6; continue; } if (n % 3 == 0) { cnt++; n = n * 2; } else { cnt = -1; break; } } cout << cnt << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, c1 = 0; cin >> n; while (n % 6 == 0) { c1++; n /= 6; } while (n % 3 == 0) { c1 = c1 + 2; n = n / 3; } if (n != 1) cout << -1 << endl; else cout << c1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, ans; int two = 0, three = 0; cin >> n; while (n % 2 == 0) { two++; n /= 2; } while (n % 3 == 0) { three++; n /= 3; } if (two > three || n > 1) cout << "-1"; else if (three > two) cout << three + (three - two); else cout << three; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, a, colv2 = 0, colv3 = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> a; colv2 = 0; colv3 = 0; while (a % 2 == 0) { a /= 2; colv2++; } while (a % 3 == 0) { a /= 3; colv3++; } if (a == 1 && colv2 <= colv3) { cout << (colv3 - colv2) + colv3 << "\n"; } else cout << -1 << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, two = 0, three = 0, moves = 0, hold; cin >> t; for (int i = 0; i < t; i++) { cin >> n; two = 0; three = 0; moves = 0; while (true) { hold = n; if (n % 2 == 0) { two++; n = n / 2; } if (n % 3 == 0) { three++; n = n / 3; } if (hold == n) break; } if (three < two || n != 1) { cout << -1 << endl; } else { moves += (three - two); moves += three; cout << moves << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long p = n; int a = 0, s = 0; while (p > 1) { if (p % 6 == 0) { a++; p /= 6; } else break; } while (p > 1) { if (p % 3 == 0) { a += 2; p /= 3; } else { s++; break; } } if (s == 1) cout << "-1\n"; else cout << a << "\n"; } }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, ans = 0; cin >> n; for (;; ans++) { if (n == 1) break; if (n % 6 == 0) n /= 6; else if (n % 3 == 0) { if ((n * 2) % 3 != 0) { cout << "-1\n"; return; } n *= 2; } else { cout << "-1\n"; return; } } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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, s = 0, d = 0; cin >> n; bool six = true; while (n != 1) { if (n % 2 == 0) { n /= 2; d++; } else if (n % 3 == 0) { n /= 3; s++; } else if (n % 3 != 0 && n % 2 != 0) { six = false; break; } } if (s >= d && six) cout << (2 * s) - d << endl; else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; string yes[3] = {"YES", "Yes", "yes"}; string no[3] = {"NO", "No", "no"}; int countones(long long a) { int count = 0; while (a != 0) { count++; a = a & (a - 1); } return count; } unsigned int reverse_bits(register unsigned int x) { x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return ((x >> 16) | (x << 16)); } long long Fib[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903}; long long sum(long long n) { return (n * (n + 1)) / 2; } long long rangesum(long long a, long long b) { if (a <= 1) return sum(b); return sum(b) - sum(a - 1); } bool isPowerOfTwo(int n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } inline bool cmp(long long a, long long b) { return a > b; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int t, n, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> t; while (t--) { ans = 0; cin >> n; while (n > 1) { if (n % 6 == 0) { n /= 6; ++ans; } else { n *= 2; ++ans; if (n % 6 != 0) { ans = -1; break; } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, cnt = 0, cnt2 = 0; cin >> n; while (n % 3 == 0) { n /= 3; cnt++; } while (n % 2 == 0) { n /= 2; cnt2++; } if (n > 1) { cout << -1 << "\n"; } else if (cnt < cnt2) { cout << -1 << "\n"; } else { long long x = cnt - cnt2; cout << cnt + x << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 100005; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long i, j, k, n, m, ans = 0, cnt = 0, sum = 0; cin >> n; while (n % 6 == 0) { n /= 6; ans++; } while (n != 1) { if ((n * 2) % 6 == 0) { n = (n * 2) / 6; ans += 2; continue; } else { ans = -1; break; } } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> template <typename T> void scan(T &x) { x = 0; bool _ = 0; T c = getchar(); _ = c == 45; c = _ ? getchar() : c; while (c < 48 || c > 57) c = getchar(); for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15); x = _ ? -x : x; } template <typename T> void printn(T n) { bool _ = 0; _ = n < 0; n = _ ? -n : n; char snum[65]; int i = 0; do { snum[i++] = n % 10 + 48; n /= 10; } while (n); --i; if (_) putchar(45); while (i >= 0) putchar(snum[i--]); } template <typename First, typename... Ints> void scan(First &arg, Ints &...rest) { scan(arg); scan(rest...); } template <typename T> void print(T n) { printn(n); putchar(10); } template <typename First, typename... Ints> void print(First arg, Ints... rest) { printn(arg); putchar(32); print(rest...); } using namespace std; int main() { int t, n; scan(t); while (t--) { scan(n); int cnt2 = 0, cnt3 = 0; while (n % 2 == 0) { cnt2++; n /= 2; } while (n % 3 == 0) { n /= 3; cnt3++; } if (n > 1 || cnt2 > cnt3) { print(-1); continue; } print(cnt3 + cnt3 - cnt2); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, th = 0, tw = 0; cin >> n; if (n == 1) { cout << 0 << endl; continue; } while (n % 2 == 0) { tw++; n = n / 2; } while (n % 3 == 0) { th++; n = n / 3; } if (n > 1) cout << -1 << endl; else { if (th == tw) cout << th << endl; else if (th < tw) cout << -1 << endl; else cout << (th - tw) + th << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pr = pair<int, int>; using prll = pair<long, long>; using V = vector<int>; using Vll = vector<long long>; template <typename T, typename TT> pr operator+(pair<T, TT> a, pair<T, TT> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename TT> ostream& operator<<(ostream& s, pair<T, TT> t) { return s << "(" << t.first << "," << t.second << ")"; } template <typename T> ostream& operator<<(ostream& s, vector<T> t) { for (auto itr : t) s << itr << " "; return s; } int main() { int T; cin >> T; while (T--) { int n; cin >> n; int x = 0; while (n > 1 && n % 6 == 0) { n /= 6; x++; } int ans = x; int y = 0; while (n > 1 && n % 3 == 0) { n /= 3; y++; } ans += 2 * y; if (n == 1) cout << ans << "\n"; else cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (long long i = 0; i < t; i++) { long long n; cin >> n; if (n == 1) cout << 0 << endl; else { if (n % 3 == 0) { long long num = n, count = 0; while (num % 3 == 0) { num /= 3; count++; } if (num == 1) cout << 2 * count << endl; else { if (num % 2 == 0) { long long sum = 0; while (num % 2 == 0) { num /= 2; sum++; } if (num == 1) { long long d; if (sum <= count) { d = count - sum; cout << count + d << endl; } else cout << -1 << endl; } else cout << -1 << endl; } else cout << -1 << endl; } } else cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll x, y, n; map<ll, bool> pq; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int ts; cin >> ts; while (ts--) { cin >> n; if (ts == 0) { ts = 0; } ll ans = 0; pq.clear(); while (n % 6 == 0 && n != 1) { ans++; pq[n] = 1; n /= 6; } if (n != 1) { bool can = 0; while (true) { while (n % 6 && n < INT_MAX) { n *= 2; ans++; if (pq[n]) { can = 1; ans = -1; break; } pq[n] = 1; } if (can or n >= INT_MAX) { break; } if (ans == -1) { cout << -1 << endl; continue; } while (n % 6 == 0 && n != 1) { ans++; n /= 6; if (pq[n]) { can = 1; ans = -1; break; } pq[n] = 1; } if (can) { break; } if (n == 1) { goto l1; } } } l1: 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(false); cin.tie(NULL); int t; cin >> t; int n; while (t-- > 0) { cin >> n; int c3 = 0; int c2 = 0; while (n % 2 == 0) { n = n / 2; c2++; } while (n % 3 == 0) { n = n / 3; c3++; } if (n != 1) cout << -1 << "\n"; else { if (c2 > c3) cout << -1 << "\n"; else cout << ((2 * c3) - c2) << "\n"; } } }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") vector<long long int> v; vector<long long int> w, ab, bc; set<long long int> uo; map<long long int, long long int> ww, cc, u; vector<pair<long long int, long long int> > uu; map<long long int, vector<long long int> > uuu; map<pair<long long int, long long int>, long long int> vo; map<pair<long long int, long long int>, long long int> vu; long long int br[10005]; long long int dxx[] = {-1, 0, 1, 0}; long long int dyy[] = {0, 1, 0, -1}; long long int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}; long long int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char ch; string a, b, c; double x, y, d, e, f, g, h; long long int n, m, i, j, k, p, q, o, l, s, tt = 1, t, z, aa, r = 0; for (i = 1, l = 0; i <= 100000000000000000; i *= 6, l++) { v.push_back(i); } cin >> tt; while (tt--) { cin >> n; for (i = 0, k = 4e18; i < v.size(); i++) { if (v[i] >= n) { s = v[i]; t = 0; while (1) { if (s > n && s % 2 == 0) { t++; s /= 2; } else { break; } } if (s == n) { k = min(i + t, k); } } } if (k == 4e18) { cout << -1 << "\n"; } else { cout << k << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long cnt = 0; int k = n; int a = 0, b = 0; while (1) { if (k % 2 != 0) break; k /= 2; a++; } while (1) { if (k % 3 != 0) break; k /= 3; b++; } if (a > b || k != 1) { cout << -1 << '\n'; } else { cout << a + 2 * (b - a) << '\n'; } } }
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { int t; cin >> t; while (t--) { long long int n, m, i, ans = 0, j, f = 0, x, c = 0; cin >> n; if (n == 1) { cout << "0" << endl; continue; } for (i = 0; i < 30; i++) { j = n * pow(2ll, i); c = 1ll; x = 6ll; while (x <= j && x > 0) { x = pow(6ll, c); if (j % x == 0 && j / x == 1) { ans = i + c; f = 1; break; } else c++; } if (f == 1) break; } if (ans == 0) cout << "-1" << endl; else cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename... T> void read(T&... a) { ((cin >> a), ...); } template <typename... T> void write(T&... a) { ((cout << a << " "), ...); cout << "\n"; } void solve() { long long n; cin >> n; int cnt = 0; while (1) { if (n < 6) { if (n == 3) { cout << cnt + 2 << "\n"; break; } else if (n == 1) { cout << cnt << "\n"; break; } else { cout << -1 << "\n"; break; } } else { if (n % 6 != 0) n *= 2; else n /= 6; } cnt++; } } 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; int nos(int n) { int c = 0; while (n != 1) { if (n % 3 != 0) { return -1; } while (n % 6 == 0) { n /= 6; c++; } if (n % 3 == 0) { n *= 2; c++; } } return c; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << nos(n) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long n, ans = 0; cin >> n; while (n > 1) { if (n % 6 == 0) { n /= 6, ans++; } else if (n % 6 == 3) { n /= 3; ans += 2; } else { break; } } if (n == 1) { cout << ans << endl; } else { if (n == 3) { cout << ans + 2 << endl; } else { cout << -1 << endl; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x; cin >> x; int res = 0; while (x != 1) { if (x % 6 == 0) { x = x / 6; res++; } else if (x % 3 == 0) { x = x / 3; res = res + 2; } else { break; } } if (x == 1) cout << res << endl; else cout << "-1" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, y, a, b, ans; long long int t; ios_base::sync_with_stdio(); cin.tie(NULL); cout.tie(NULL); ; cin >> t; while (t--) { a = 0; cin >> n; while (n != 1) { if (n % 6 == 0) n = n / 6; else if (n % 2 == 1) n = n * 2; else break; a++; } if (n == 1) cout << a << endl; else cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x; cin >> x; int count = 0; while (x != 1) { if (x % 6 == 0) { count++; x /= 6; } else if (x % 3 == 0) { x *= 2; count++; } else { cout << -1 << endl; break; } } if (x == 1) cout << count << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t, n, out; cin >> t; while (t--) { out = 0; cin >> n; while (n > 1) { if (n % 6 == 0) { n = n / 6; out += 1; } else if (n % 3 == 0) { n = n * 2; out += 1; } else { out = -1; break; } } cout << out << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; long long a, j = 0, ans = 0; for (int i = 0; i < t; ++i) { cin >> a; while (true) { if (a == 1) break; if (a % 2 != 0) { a *= 2; ++j; continue; } if (a % 6 == 0) { a /= 6; ++j; continue; } else { ans = -1; break; } } if (ans != -1) ans = j; cout << ans << endl; ans = 0; j = 0; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int cnt = 0; while (n % 6 == 0) { n /= 6; cnt++; } while (n % 3 == 0) { n /= 3; cnt += 2; } if (n == 1) { cout << cnt << endl; } else cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int fact2 = 0, fact3 = 0; while (n % 2 == 0) { n = n / 2; fact2++; } while (n % 3 == 0) { n = n / 3; fact3++; } if (n != 1) { cout << "-1\n"; continue; } if (fact3 < fact2) { cout << "-1\n"; continue; } cout << fact3 + abs(fact3 - fact2) << '\n'; } }
#include <bits/stdc++.h> using namespace std; int check(int n) { vector<int> v; if (n == 1) return 0; int cnt = 0; while (true) { if (n % 6 == 0) { n /= 6; cnt++; } else if (n % 6 != 0) { n *= 2; cnt++; } if (n == 1) return cnt; else if (n % 6 == 2 || n % 6 == 4) return -1; else if (find(v.begin(), v.end(), n) == end(v)) v.push_back(n); else return -1; } } int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << check(n) << endl; } return 0; }
#include <bits/stdc++.h> int main(void) { int n, step; scanf("%d", &n); int x[n]; for (int i = 0; i < n; i++) { step = 0; scanf("%d", &x[i]); while (x[i]) { if (x[i] == 1) { break; } step++; x[i] % 6 == 0 ? x[i] /= 6 : (x[i] % 3 != 0 ? step = -1, x[i] = 0 : (x[i] *= 2)); } x[i] = step; } for (int i = 0; i < n; i++) { printf("%d\n", x[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n; cin >> t; while (t--) { cin >> n; int d = 0, tr = 0; while (n % 2 == 0) { n /= 2; d++; } while (n % 3 == 0) { n /= 3; tr++; } if (n > 1 || d > tr) { cout << -1 << "\n"; } else { cout << tr + (tr - d) << "\n"; } } }
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int count = 0, n, flag = 0; scanf("%d", &n); if (n == 1) printf("0\n"); else { if (n % 3 != 0) printf("-1\n"); else { while (n % 3 == 0) { if (n % 6 == 0) { n = n / 6; count++; } else { n = n * 2; count++; } } if (n == 1) printf("%d\n", count); else printf("-1\n"); } } } return 0; }