|
#include <stdio.h>
#include <math.h>
typedef unsigned long pr_t;
int pr_test (pr_t x)
{
pr_t i, sqx = (pr_t) sqrt (x);
for (i = 3; i <= sqx; i + = 2)
if (x% i == 0)
return 0;
return 1;
}
int slove (pr_t * p, pr_t * t, int n)
{
int r = 0, i, j;
for (i = 0; i <n; ++ i)
for (j = 1; j <= 9; j + = 2)
if (pr_test (p [i] * 10 + j))
t [r ++] = p [i] * 10 + j;
return r;
}
#define BUFF_SIZE (200)
int main ()
{
pr_t b1 [BUFF_SIZE] = {2, 3, 5, 7}, b2 [BUFF_SIZE];
pr_t * p = b1, * t = b2, * tt;
int n = 4, i;
while (n)
{
for (i = 0; i <n; ++ i)
printf ("% -10d", p [i]);
n = slove (p, t, n);
tt = p; p = t; t = tt;
}
printf ("\n\n");
return 0;
} |
|