Computer Programming Contest Preparation

ToolBox - Source for: 105/10533/c.c



/home/toolbox/public_html/solutions/105/10533/c.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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 10-19-2021
   21  * Purpose: fun
   22  * Problem: 10533 - Digit Primes
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 int numberOfTimes;
   30 
   31 #define MAX_SIZE 500000
   32 #define LARGEST 1000000
   33 #define MAX_DIGIT_SIZE 10000
   34 
   35 int num;
   36 int numPrimes;
   37 int primes[MAX_SIZE];
   38 int numDigitPrimes;
   39 int digitPrimes[MAX_DIGIT_SIZE];
   40 
   41 void init()
   42 {
   43     /* FUNCTION init */
   44     int i;
   45     int j;
   46 
   47     numPrimes = 1;
   48     primes[0] = 2;
   49 
   50     /* sieve of erasthones (odds only) */
   51     for (i=1,j=3; MAX_SIZE>i; i=i+1,j=j+3)
   52         {
   53             primes[i]=j;
   54         }
   55     for (i=1; MAX_SIZE>i; i=i+1)
   56         {
   57             /* loop through primes */
   58             if (0 != primes[i])
   59                 {
   60                     /* found a prime */
   61                     primes[numPrimes] = primes[i];
   62                     numPrimes++;
   63                     for (j=i+primes[i]; j<MAX_SIZE; j=j+primes[i])
   64                         {
   65                             /* mark out multiples */
   66                             primes[j] = 0;
   67                         } /* mark out multiples */
   68                 } /* found a prime */
   69         } /* loop through primes */
   70     printf("NUmber of primes %d\n", numPrimes);
   71     /* find digit primes */
   72     digitPrimes[0] = 2;
   73     digitPrimes[1] = 3;
   74     digitPrimes[2] = 5;
   75     digitPrimes[3] = 7;
   76     numDigitPrimes = 4;
   77     for (i=4; numPrimes>i; i++)
   78         {
   79             /* for each prime */
   80             if (digitPrime(primes[i]))
   81                 {
   82                     /* keep digitPrime */
   83                 } /* for each prime */
   84             /* get count of inputs */
   85             scanf("%d ", &numberOfTimes);
   86         } /* FUNCTION init */
   87 
   88     void dump()
   89     {
   90         /* FUNCTION dump */
   91     } /* FUNCTION dump */
   92 
   93     void getInput()
   94     {
   95         /* FUNCTION getInput */
   96     } /* FUNCTION getInput */
   97 
   98     void process()
   99     {
  100         /* FUNCTION process */
  101     } /* FUNCTION process */
  102 
  103     int main()
  104     {
  105         /* main */
  106         int i;
  107 
  108         init();
  109         for (i=0; i<numberOfTimes; i++)
  110             {
  111                 /* while */
  112                 getInput();
  113                 process();
  114             } /* while */
  115 
  116         return EXIT_SUCCESS;
  117     } /* main */
  118 
  119