-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL_DivideIt.java
More file actions
60 lines (48 loc) · 1.23 KB
/
L_DivideIt.java
File metadata and controls
60 lines (48 loc) · 1.23 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// #include <bits/stdc++.h>
// #include <iostream>
// using namespace std;
// int main()
// {
// int count;
// long long int num;
// int moves;
// cin >> count;
// for (int i = 0; i < count; i++)
// {
// moves =0;
// cin >> num;
// while(num%2==0 || num%3==0 || num%5==0){
// moves++;
// if (num%2==0)
// num/=2;
// else if(num%3==0)
// num = (2*num)/3;
// else if(num%5==0)
// num = (4*num)/5;
// }
// cout << ((num == 1) ? moves : -1 )<< endl;
// }
// return 0;
// }
import java.util.Scanner;
public class L_DivideIt {
public static void main(String[] args) {
int count;
long num;
int moves;
Scanner input = new Scanner(System.in);
count = input.nextInt();
for (int i = 0; i < count; i++) {
moves = 0;
num = input.nextLong();
while (num % 2 == 0 || num % 3 == 0 || num % 5 == 0) {
moves++;
if (num % 2 == 0) num /= 2;
else if (num % 3 == 0) num =(2 * num) / 3;
else if (num % 5 == 0) num = (4 * num) / 5;
}
System.out.println(((num == 1) ? moves : -1));
}
input.close();
}
}