-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm263.java
More file actions
35 lines (31 loc) · 818 Bytes
/
prblm263.java
File metadata and controls
35 lines (31 loc) · 818 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
public class prblm263 {
public static void main(String[] args) {
int n = 6;
System.out.println(new prblm263().isUgly(n));
int n2 = 14;
System.out.println(new prblm263().isUgly(n2));
int n3 = 8;
System.out.println(new prblm263().isUgly(n3));
}
public boolean isUgly(int n) {
for(int i = 2; i < n; i++){
if(n % i == 0 && (i != 2 && i != 3 && i != 5)){
return false;
}
}
return true;
}
public boolean isUgly2(int n) {
if (n < 1) return false;
while(n % 2 == 0) {
n /= 2;
}
while (n % 3 == 0) {
n /= 3;
}
while(n % 5 == 0) {
n /= 5;
}
return n == 1;
}
}