-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP37.java
47 lines (41 loc) · 866 Bytes
/
P37.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
package euler;
import java.util.Collections;
import java.util.List;
public class P37
{
public static void main(String[] args)
{
long start=System.currentTimeMillis();
List<Integer> primes = P3_Prime.primes(800000);
int sum=0;
for (int p: primes)
{
if (p<11)
continue;
//System.out.print(p+": truncating =>");
boolean skip=false;
int x=p;
while (!skip && x>0)
{
if (Collections.binarySearch(primes,x)<0)
skip=true;
x /= 10;
}
x=p;
while (!skip && x>0)
{
if (Collections.binarySearch(primes,x)<0)
skip=true;
int order = (int)Math.pow(10,(int)Math.log10(x));
x %= order;
}
if (!skip)
{
System.out.println(" *** Truncatable=" + p);
sum += p;
}
}
long end=System.currentTimeMillis();
System.out.format("In %,dms, found sum=%,d%n",(end-start),sum);
}
}