|
An n-digit super prime number refers to an n-digit positive integer. The first 1, the first 2 digits,..., And the first n digits are all prime numbers. For example, 7331 is a 4-digit super prime number because 7, 73, 733, 7331 are prime numbers.
#include <stdio.h>
#include <math.h>
#define DEEP 10000 //is the loop depth
int isPrime(int p);
int isSuperPrime(int p);
int isSuperPrime(int p)
{
if(isPrime(p)&&p>10)
{
while(p>10)
{
p/=10;
if(!(isPrime(p)))
return 0;
}
return 1;
}
return 0;
}
int isPrime(int p)
{
int a,i;
if(p<2)
return 0;
else if(p==2)
return 1;
a=(int)sqrt(p+1);
for(i=2;i<=a;i++)
if(!(p%i))
return 0;
return 1;
}
int main()
{
int i;
for(i=2;i<DEEP;i++)
if(isSuperPrime(i))
printf("%d\t",i);
getch();
return 0;
} |
|