-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler87.java
46 lines (33 loc) · 914 Bytes
/
Euler87.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
import java.util.*;
public class Euler87 {
public static void main(String[] arg) {
int answer = 0;
int limit = 50000000;
Set<Integer> set = new HashSet<Integer>();
List<Integer> list = PrimeGenerator.generate(7072);
Iterator<Integer> it1 = list.iterator();
while(it1.hasNext()) {
int a = it1.next();
int aSum = a * a;
if(aSum > limit)
break;
Iterator<Integer> it2 = list.iterator();
while(it2.hasNext()) {
int b = it2.next();
int bSum = aSum + b*b*b;
if(bSum > limit)
break;
Iterator<Integer> it3 = list.iterator();
while(it3.hasNext()) {
int c = it3.next();
int cSum = bSum + c*c*c*c;
if(cSum > limit)
break;
if(set.add(cSum))
answer++;
}
}
}
System.out.println(answer);
}
}