(Java)
import java.math.BigInteger;
public class delicateprimes {
public static void main(String[] args) {
BigInteger i, reci=new BigInteger("0");
i= new BigInteger("1");
long count=0, v, rec=-1;
for(long loop=1;; loop++)
{
i=i.nextProbablePrime();
v = delicate(i, true);
if(v>rec) {count++; rec=v; reci=i; System.out.println("REC=("+reci+", "+rec+") " +loop +" "+count); }
if(loop%100000==0)System.out.println("Still running, last prime seen was "+i);
}
}
static int delicate(BigInteger a, boolean f) // Returns how many digits can be tacked on the delicate prime. f=false just tests the prime with no extra 0s
{
int e, length, max=200;
if(!f)max=1;
String num="", num2="";
if(!prime(a))return -1;
for(e=0; e<max; e++) //While widely digitally delicate primes do exist, this needs to have a stop point
{
num=zeros(e)+a.toString();
if(e>0)length=e; else length = num.length();
for(int j=0; j<length; j++)
{
for(int k=0; k<=9; k++)
{
num2=num.substring(0, j)+k+num.substring(j+1);
if(num2.contentEquals(num))continue;
if(prime(new BigInteger(num2))) {return e-1; }
}
}
}
return e-1;
}
static boolean prime(BigInteger a)
{
return a.isProbablePrime(100);
}
static String zeros(int n)
{
StringBuffer temp=new StringBuffer("");
for(int i=0; i<n; i++)temp=temp.append("0");
return temp.toString();
}
}
|