The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of 3 and 1,000,000,000.
Output
The list of palindromic primes in numerical order, one per line. Then print the run time (seconds) at the last line.
我写了一个,大家帮我run一下.
#include "stdio.h"
int main()
{
int i,n,j,k,count=0,lower,upper,integer,array[10];
for(i=100;i<1000000000;++i)
{
integer=i;
n=(int) integer/2;
for(j=2;j<=n;++j)
if(i%j==0)
break;
if(j>n)
{
k=0;
while((integer%10!=0) ||(integer/10!=0))
{
array[k]=integer%10;
integer=integer/10;
k++;
}
lower=0;
upper=--k;
while(lower<upper)
{
if(array[lower]!=array[upper])
break;
lower++;
upper--;
}
if(lower>=upper)
{
printf("%10d",i);
count++;
}
if(count==8)
{
printf("\n");
count=0;
}
}
}
return 0;
}