-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler060.java
More file actions
executable file
·70 lines (60 loc) · 1.86 KB
/
Copy pathEuler060.java
File metadata and controls
executable file
·70 lines (60 loc) · 1.86 KB
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
70
import java.util.Date;
/*
Project Euler Problem 60
========================
The primes 3, 7, 109, and 673, are quite remarkable. By taking any two
primes and concatenating them in any order the result will always be
prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The
sum of these four primes, 792, represents the lowest sum for a set of four
primes with this property.
Find the lowest sum for a set of five primes for which any two primes
concatenate to produce another prime.
*/
public class Euler060 {
public static void main(String[] args) {
Date start, end;
start = new Date();
int[] primes = { 5, 3, 3, 3 };
int i = 0, j = 0, k = 0, l = 0;
for (i = 0; i <= primes[0];) {
for (j = 0; j <= i; j++) {
for (k = 0; k <= i; k++) {
for (l = 0; l <= i; l++) {
}
}
while (!isPrime(++i))
;
}
}
while (!isPrime(++i));
System.out.printf("%d %d %d %d\n", i, j, k, l);
end = new Date();
System.out.println();
System.out.println("Execution time: "
+ (end.getTime() - start.getTime()));
}
public static boolean isPrime(long num) {
if (num == 0 || num == 1)
return false;
if (num < 4)
return true;
if (num % 2 == 0)
return false;
if (num < 9)
return true;
if (num % 3 == 0)
return false;
else {
int sqrt = (int) Math.floor(Math.sqrt(num));
int f = 5;
while (f <= sqrt) {
if (num % f == 0)
return false;
if (num % (f + 2) == 0)
return false;
f += 6;
}
return true;
}
}
}