-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplyanddivide.java
More file actions
35 lines (34 loc) · 927 Bytes
/
multiplyanddivide.java
File metadata and controls
35 lines (34 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.*;
import java.util.*;
public class multiplyanddivide {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int two=0,three=0;
while(n%2==0){
n/=2;
two++;
}
while(n%3==0){
n/=3;
three++;
}
if(n>1)sb.append(-1);
else{
if(two==three)sb.append(two);
else if(two>three)sb.append(-1);
else{
int ans=(three-two);
two+=(three-two);
ans+=three;
sb.append(ans);
}
}
sb.append("\n");
}
System.out.println(sb);
}
}