1: /**
2: * @file 033cprime.c
3: * @author Chaolong Zhang @163.com>
4: * @date Wed Jun 5 18:37:44 2013
5: *
6: * @brief 回文素数:求不超过1000的回文素数。所谓回文素数是指,对一个整数n从左向右和从右向左读都是一样的素数。
7: *
8: *
9: */
10: #include
11: int is_prime( int );
12:
13: int main(int argc, char *argv[])
14: {
15: int i,j,t,k,s;
16: printf ("Following are palindrome primes not greater than 1000\n");
17: for (i=0; i<=9 ; i++)
18: {
19: for (j=0; j <= 9; j++)
20: {
21: for (k=0; k <= 9; k++)
22: {
23: s=i*100 + j*10 + k;
24: t=k*100 + j*10 + i;
25: if( 0==i && 0 == j ) t/=100;
26: else if( 0 == i ) t/=10;
27: if (( s > 10 ) && ( s == t ) && is_prime( s ) )
28: printf ("%d\t\n",s);
29: }
30:
31: }
32:
33: }
34: return 0;
35: }
36:
37:
38: int is_prime ( int n )
39: {
40: int i;
41: int flag=1;
42: if (n==2 || n==3)
43: return flag;
44: for ( i = 2; i <= ( n/2 + 1 ); ++i)
45: if (n%i == 0 ) {
46: flag=0;return flag;
47: }
48: }