Computer Programming Contest Preparation

ToolBox - Source for: 101/10179/a.c



/home/toolbox/public_html/solutions/101/10179/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date:
   19  * Purpose: fun
   20  * Problem: 10179
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 int n;
   28 
   29 void init()
   30 {
   31     /* FUNCTION init */
   32 } /* FUNCTION init */
   33 
   34 void dump()
   35 {
   36     /* FUNCTION dump */
   37 } /* FUNCTION dump */
   38 
   39 int getInput()
   40 {
   41     /* FUNCTION getInput */
   42     int dataReadFlag;
   43 
   44     scanf(" %d ", &n);
   45     dataReadFlag = 0 != n;
   46     return (dataReadFlag);
   47 } /* FUNCTION getInput */
   48 
   49 int gcd(int a, int b)
   50 {
   51     /* FUNCTION gcd */
   52     /* this uses Euclid's method */
   53     int toReturn;
   54 
   55     if (0 == b)
   56         toReturn = a;
   57     else
   58         toReturn = gcd(b, (a % b));
   59     return toReturn;
   60 } /* FUNCTION gcd */
   61 
   62 void process()
   63 {
   64     /* FUNCTION process */
   65     int i;
   66     int cnt;
   67     int tmp;
   68 
   69     cnt = 0; /* 0th case */
   70     for (i=1; n>i; i++)
   71         {
   72             /* for each numerator */
   73             printf("(i %d) (tmp %d) (n %d) (cnt %d)\n", i, tmp, n, cnt);
   74             tmp = gcd(i, n);
   75             if (1 == tmp)
   76                 {
   77                     cnt++;
   78                 }
   79         } /* for each numerator */
   80     printf("%d\n", cnt);
   81 } /* FUNCTION process */
   82 
   83 int main()
   84 {
   85     /* main */
   86     int moreToDo;
   87 
   88     init();
   89     moreToDo = getInput();
   90     while (moreToDo)
   91         {
   92             /* while */
   93             process();
   94             moreToDo = getInput();
   95         } /* while */
   96 
   97     return EXIT_SUCCESS;
   98 } /* main */
   99