Computer Programming Contest Preparation

ToolBox - Source for: 127/12791/b.c



/home/toolbox/public_html/solutions/127/12791/b.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 
   15 /*
   16  *  Author: Isaac Traxler
   17  *    Date: 2015-09-29
   18  * Purpose: fun
   19  * Problem: 12791
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 
   27 
   28 #define MAX_PRIMES 27
   29 #define MAX_SIZE 50
   30 #define MAX_BUFFER 52
   31 
   32 int buff[MAX_BUFFER];
   33 int primes[MAX_PRIMES];
   34 int primeCnt;
   35 int x;
   36 int y;
   37 
   38 
   39 void init()
   40 {
   41     /* FUNCTION init */
   42     int i;
   43     int j;
   44 
   45     primes[0] = 2;
   46     primeCnt = 1;
   47 
   48     /* sieve of erasthones */
   49     for (i=0,j=3; i<MAX_SIZE; i++,j=j+2)
   50         {
   51             buff[i]=j;
   52         }
   53     for (i=0; (MAX_PRIMES>primeCnt)&&(MAX_SIZE>i); i++)
   54         {
   55             /* loop through primes */
   56             if (0 != buff[i])
   57                 {
   58                     /* found a prime */
   59                     DEBUG printf("%d -- buff[%d] = %d\n", primeCnt, i, buff[i]);
   60                     primes[primeCnt++] = buff[i];
   61                     for (j=i+buff[i]; j<MAX_SIZE; j=j+buff[i])
   62                         {
   63                             /* mark out multiples */
   64                             buff[j] = 0;
   65                         } /* mark out multiples */
   66                 } /* found a prime */
   67         } /* loop through primes */
   68     printf("pime cnt %d\n", primeCnt);
   69 } /* FUNCTION init */
   70 
   71 void dump()
   72 {
   73     /* FUNCTION dump */
   74 } /* FUNCTION dump */
   75 
   76 int getInput()
   77 {
   78     /* FUNCTION getInput */
   79     int dataReadFlag;
   80 
   81     dataReadFlag = (2 == scanf(" %d %d ", &x, &y));
   82     return (dataReadFlag);
   83 } /* FUNCTION getInput */
   84 
   85 void process()
   86 {
   87     /* FUNCTION process */
   88     int cmmn = 1;
   89     int sqr;
   90     printf("%d  %d\n", x, y);
   91 } /* FUNCTION process */
   92 
   93 int main()
   94 {
   95     /* main */
   96     int moreToDo;
   97 
   98     init();
   99     moreToDo = getInput();
  100     while (moreToDo)
  101         {
  102             /* while */
  103             process();
  104             moreToDo = getInput();
  105         } /* while */
  106 
  107     return EXIT_SUCCESS;
  108 } /* main */
  109