-
Notifications
You must be signed in to change notification settings - Fork 1
/
Factovisors.java
57 lines (44 loc) · 1.87 KB
/
Factovisors.java
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
import java.util.Scanner;
public class Factovisors {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
next: while (sc.hasNext()) {
int n = sc.nextInt();
int m = sc.nextInt();
if (m == 0) {
System.out.println(m + " does not divide " + n +"!");
continue;
}
if (m ==1) {
System.out.println(m + " divides " + n +"!");
continue;
}
if (m <= n) {
System.out.println(m + " divides " + n +"!");
continue;
}
int temp = m;
int count = 0;
for (int factor = 2; factor <= (int)Math.ceil(Math.sqrt(m)); factor++) {
while (m % factor == 0) {
m /= factor;
count++;
}
if (count > 0) {
for (int j = factor; j <= n; j *= factor) {
count -= n / j;
}
if (count > 0) {
System.out.println(temp + " does not divide " + n +"!");
continue next;
}
}
count = 0;
}
if (m <= n)
System.out.println(temp + " divides " + n + "!");
else
System.out.println(temp + " does not divide " + n + "!");
}
}
}