Advertisement
Niloy007

Rafi's Code

Jun 28th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define dbgA2(A, n, m)                    \
  4.     {                                     \
  5.         cout << "-->" << #A << "=\n";     \
  6.         for (int i = 0; i < n; i++) {     \
  7.             for (int j = 0; j < n; j++) { \
  8.                 cout << A[i][j] << " ";   \
  9.             }                             \
  10.             cout << "\n";                 \
  11.         }                                 \
  12.         cout << "\n";                     \
  13.     }
  14. #define dbgA(A, n)                   \
  15.     {                                \
  16.         cout << "-->" << #A << "=("; \
  17.         for (int i = 0; i < n; i++)  \
  18.             cout << A[i] << " ";     \
  19.         cout << ")\n";               \
  20.     }
  21. #define dbg(args...)                                  \
  22.     {                                                 \
  23.         string sss(#args);                            \
  24.         sss += ',';                                   \
  25.         cout << "-->";                                \
  26.         debugger::call(sss.begin(), sss.end(), args); \
  27.         cout << "\n";                                 \
  28.     }
  29. using namespace std;
  30.  
  31. struct debugger {
  32.     typedef string::iterator si;
  33.     static void call(si it, si ed) {}
  34.     template<typename T, typename... aT>
  35.     static void call(si it, si ed, T a, aT... rest) {
  36.         string b;
  37.         for (; *it != ','; ++it)
  38.             if (*it != ' ')
  39.                 b += *it;
  40.         cout << b << "=" << a << " ";
  41.         call(++it, ed, rest...);
  42.     }
  43. };
  44. /***********************************************************************/
  45.  
  46. int main() {
  47.     ios_base::sync_with_stdio(false);
  48.     cin.tie(NULL);
  49.     int t, a;
  50.     cin >> t;
  51.     //   long long int m=1000000000;
  52.     while (t--) {
  53.         int n, cnt = 0, flag = 0;
  54.         cin >> n;
  55.  
  56.         while (n % 3 == 0) {
  57.             if (n % 6 != 0) {
  58.                 n = n * 2;
  59.                 cnt++;
  60.                 if (n % 6 == 0) {
  61.                     n = n / 6;
  62.                     cnt++;
  63.                     flag = 1;
  64.                 }
  65.             }
  66.             if (n % 6 == 0) {
  67.                 n = n / 6;
  68.                 cnt++;
  69.                 flag = 1;
  70.             }
  71.             if (flag == 0)
  72.                 break;
  73.         }
  74.         if (n == 1)
  75.             cout << cnt << endl;
  76.         else
  77.             cout << "-1" << endl;
  78.     }
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement