-
Notifications
You must be signed in to change notification settings - Fork 0
/
blatt6.java
55 lines (39 loc) · 1.06 KB
/
blatt6.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
import java.util.Set;
import java.util.TreeSet;
import java.util.Iterator;
public class blatt6 {
public static void main(String[] args) {
//test method aufgabe18
TreeSet<Integer> t = aufgabe18(33);
Iterator<Integer> it = t.iterator();
while(it.hasNext()){
System.out.print(" " + it.next());
}
}
public static Set<Integer> aufgabe17() {
while(set.size() < 7){
set.add((int) (Math.random() * 49 + 1));
}
return set;
}
public static TreeSet<Integer> aufgabe18(int n) {
TreeSet<Integer> t = new TreeSet<Integer>();
for (int i = 2; i < n; i++) {
t.add(i);
}
TreeSet<Integer> s = new TreeSet<>();
int p = 2;
while(p*p < n){
for (int i = 2; i*p < n; i++) {
s.add(p*i);
}
if(p==2){
p = 3;
} else {
while(s.contains(p+=2)){}
}
}
t.removeAll(s);
return t;
}
}