The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this sequence?
#define N 10
#define M 10000
bool isPrime(int x)
{
for (int i = 2; i*i <= x; i++)
{
if (x%i == 0)
{
return false;
}
}
return true;
}
bool check(int c1,int c2,int c3)
{
int n1[N]={0},n2[N]={0},n3[N]={0};
for (int i = 0; i < 4; i++)
{
n1[c1%10]++;
n2[c2%10]++;
n3[c3%10]++;
c1 /= 10;
c2 /= 10;
c3 /= 10;
}
for (i = 0; i < N; i++)
{
if (n1[i] != n2[i] || n1[i] != n3[i] || n2[i] != n3[i])
{
return false;
}
}
return true;
}
int main()
{
clock_t ts,te;
ts=clock();
int answer = 0;
bool b = true;
int i,j;
for (i = 1488; i < M-6660 ;b = true,i++)
{
for (j = i; j <= i+6660; j+=3330)
{
if (isPrime(j) == false)
{
b =false;
break;
}
}
if (b == true)
{
if (check(i,i+3330,i+6660) == true)
{
answer = i;
break;
}
}
}
printf("\nanswer %d%d%d",answer,answer+3330,answer+6660);
te=clock();
printf("\ntime difference: %ds\n",(te-ts)/CLOCKS_PER_SEC);
getchar();
return 0;
}