Advertisement
jakaria_hossain

codeforces - multiply by 2 divide by 6

Jun 28th, 2020
1,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  6. #define pi pair<int , int>
  7. #define mp make_pair
  8. #define f first
  9. #define s second
  10.  
  11. int main()
  12. {
  13.     fast();
  14.     ll t;
  15.     cin>>t;
  16.     while(t--)
  17.     {
  18.         ll n;
  19.         cin>>n;
  20.         ll cnt=0;
  21.         while(n>1)
  22.         {
  23.             if(n%6==0)
  24.             {
  25.                 n/=6;
  26.                 cnt++;
  27.             }
  28.             else
  29.             {
  30.                 n*=2;
  31.                 cnt++;
  32.                 if(n%6==0)continue;
  33.                 else break;
  34.             }
  35.         }
  36.         if(n==1)cout<<cnt<<endl;
  37.         else cout<<-1<<endl;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement