Truncatable primes: Difference between revisions

(Added Java Implementation.)
Line 355:
//Sieve ends...
 
//Find Largest TruncableTruncatable Prime. (so we start from 1000000 - 1
int rightTrunc = -1, leftTrunc = -1;
for(int prime = (MAX - 1) | 1; prime >= 3; prime -= 2)
Line 361:
if(primeList.get(prime>>1))
{
//Already found Right TruncableTruncatable Prime?
if(rightTrunc == -1)
{
Line 369:
}
 
//Already found Left TruncableTruncatable Prime?
if(leftTrunc == -1 )
{
//Left Truncation
String left = StringInteger.valueOftoString(prime);
if(!left.contains("0"))
{
Line 390:
}
}
System.out.println("Left TruncableTruncatable : " + leftTrunc);
System.out.println("Right TruncableTruncatable : " + rightTrunc);
}
}
Line 397:
Output :
<pre>
Left TruncableTruncatable : 998443
Right TruncableTruncatable : 796339
</pre>
 
Anonymous user