Advertisement
Rofyda_Elghadban1

Untitled

Sep 7th, 2023
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. int t;
  2.  cin>>t;
  3.  while(t--){
  4.   int n,c2=0,c3=0,c=0,counter=0;
  5.   cin>>n;
  6.   for(int i=2;i<=sqrt(n);i++){
  7.     if(n%i==0){
  8.       while(n%i==0){
  9.         if(i==2){
  10.           c2++;
  11.           //cout<<i<<" ";
  12.         }else if(i==3){
  13.           c3++;
  14.           //cout<<i<<" ";
  15.         }
  16.         n/=i;
  17.       }
  18.     }
  19.   }
  20.   //cout<<"\n";
  21.   if(n>1){
  22.   if(n==2){
  23.     c2++;
  24.     n=1;
  25.   }else if(n==3){
  26.     c3++;
  27.     n=1;
  28.   }
  29.   }
  30.   //cout<<n<<"\n";
  31.   if(n>1||c3<c2){
  32.     cout<<-1<<"\n";
  33.   }else{
  34.     cout<<2*c3-c2<<"\n";
  35.   }
  36.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement