By replacing the 1st digit of *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.
Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.
#define N 1000000
bool isPrime(int x)
{
for (int n = sqrt(x),i = 2; i <= n ;i++)
{
if (x%i == 0)
{
return false;
}
}
return true;
}
int addivite(int p)
{
char c[10]={0};
int max = 0,num = 1,count = 0,ans;
sprintf(c,"%d",p);
for (int i = 0; i < strlen(c)-1; i++)
{
char temp = c[i];
num = 1,count = 1;
for (int j = i+1; j < strlen(c); j++)
{
num *= 10;
if (temp == c[j])
{
num++;
count++;
}
}
if (max < count)
{
max = count;
ans = num;
}
}
return ans;
}
int main()
{
clock_t ts,te;
ts=clock();
int answer = 0;
for (int i = 100000; i < N; i++)
{
for (int j = 1,count = 1,a = addivite(i); isPrime(i) == true && j < 10 ; j++)
{
if (isPrime(i+a*j) == true)
{
count++;
}
}
if (count == 8)
{
answer = i;
break;
}
}
printf("\nanswer %d",answer);
te=clock();
printf("\ntime difference: %ds\n",(te-ts)/CLOCKS_PER_SEC);
getchar();
return 0;
}