-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem60.java
69 lines (51 loc) · 1.12 KB
/
Problem60.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
58
59
60
61
62
63
64
65
66
67
68
69
package dimikOJ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Problem60 {
static long is_prime(long n) {
long i, root;
if (n < 2) {
return 0;
}
if (n == 2) {
return 1;
}
if (n % 2 == 0) {
return 0;
}
root = (long) Math.sqrt(n);
for (i = 3; i <= root; i += 2) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
ArrayList<Long> numbers = new ArrayList<Long>();
long num = input.nextLong();
while (num >= 0) {
numbers.add(num);
num = input.nextLong();
}
input.close();
for (Long number : numbers) {
ArrayList<Long> primes = new ArrayList<Long>();
for (long i = 2; i <= number; i++) {
if (number % i == 0) {
if (is_prime(i) == 1) {
primes.add(i);
}
}
}
Collections.sort(primes);
for (Long prime : primes) {
System.out.printf(" %d\n", prime);
}
System.out.printf("\n");
}
}
}