/home/toolbox/public_html/solutions/128/12802/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14 #define DEBUG1 if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date:
19 * Purpose: fun
20 * Problem:
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #define NUMBER int
28 #define MAX_SIZE 510000
29
30 NUMBER num;
31 NUMBER primes[MAX_SIZE+3];
32 NUMBER numPrimes;
33
34
35 void init()
36 {
37 /* FUNCTION init */
38 int i;
39 int j;
40
41 numPrimes = 1;
42 primes[0] = 2;
43
44 /* sieve of erasthones */
45 for (i=2,j=3; i<MAX_SIZE; i++,j=j+2)
46 {
47 primes[i]=j;
48 }
49 for (i=2; i<MAX_SIZE; i++)
50 {
51 /* loop through primes */
52 if (0 != primes[i])
53 {
54 /* found a prime */
55 primes[numPrimes] = primes[i];
56 numPrimes++;
57 for (j=i+primes[i]; j<MAX_SIZE; j=j+primes[i])
58 {
59 /* mark out multiples */
60 primes[j] = 0;
61 } /* mark out multiples */
62 } /* found a prime */
63 } /* loop through primes */
64 DEBUG printf("numPrimes = %d\n", numPrimes);
65 } /* FUNCTION init */
66
67 int isPrime(int num)
68 {
69 /* FUNCTION isPrime */
70 int ip;
71 int i;
72
73 if (1 == num)
74 {
75 /* 1 is considered prine */
76 ip = TRUE;
77 } /* 1 is considered prine */
78 else
79 {
80 /* not a 1 -- figure out if it is prime */
81 ip = FALSE;
82 for (i=0; ((! ip) && (i<numPrimes)); i++)
83 {
84 /* search prime list */
85 ip = (num == primes[i]);
86 } /* search prime list */
87 } /* not a 1 -- figure out if it is prime */
88 return ip;
89 } /* FUNCTION isPrime */
90
91
92 int isPalin(int num)
93 {
94 /* FUNCTION isPalin */
95 int tmp;
96 int rev;
97
98 tmp = num;
99 rev = 0;
100 while (0 < tmp)
101 {
102 /* keep going */
103 rev = (rev * 10) + (tmp % 10);
104 tmp = tmp / 10;
105 } /* keep going */
106 DEBUG1 printf("isPalin: num %d rev %d\n", num, rev);
107 return (num == rev);
108 } /* FUNCTION isPalin */
109
110 void dump()
111 {
112 /* FUNCTION dump */
113 } /* FUNCTION dump */
114
115 void getInput()
116 {
117 /* FUNCTION getInput */
118
119 scanf(" %d ", &num);
120 DEBUG1 printf("getInput: num = %d\n", num);
121 } /* FUNCTION getInput */
122
123 void process()
124 {
125 /* FUNCTION process */
126 printf("%d\n", num*2);
127 } /* FUNCTION process */
128
129 int main()
130 {
131 /* main */
132 int timeToStop = FALSE;
133 int tmp1;
134 int tmp2 = 0;
135
136 init();
137 while (! timeToStop)
138 {
139 /* while */
140 getInput();
141 if (num > 1000000)
142 {
143 tmp1 = 5 /tmp2;
144 }
145 process();
146 timeToStop = (isPrime(num) && isPalin(num));
147 } /* while */
148
149 return EXIT_SUCCESS;
150 } /* main */
151