Promi_38

cf 1374B

Jan 17th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int t;
  6.     scanf("%d", &t);
  7.    
  8.     while(t--)
  9.     {
  10.         long long int n;
  11.         scanf("%lld", &n);
  12.         int cnt2 = 0, cnt3 = 0;
  13.         while(n % 2 == 0)
  14.         {
  15.             cnt2++;
  16.             n /= 2;
  17.         }
  18.         while(n % 3 == 0)
  19.         {
  20.             cnt3++;
  21.             n /= 3;
  22.         }
  23.         if(n == 1 && cnt2 <= cnt3) printf("%d\n", 2*cnt3 - cnt2);
  24.         else printf("-1\n");
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment