Computer Programming Contest Preparation

ToolBox - Source for: 1/113/a.c



/home/toolbox/public_html/solutions/1/113/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 
   15 /*
   16  *  Author:
   17  *    Date:
   18  * Purpose:
   19  * Problem:
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int n;
   27 double p;
   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     dataReadFlag = ! feof(stdin);
   45     scanf(" %d %lf ", &n, &p);
   46     return (dataReadFlag);
   47 } /* FUNCTION getInput */
   48 
   49 void process()
   50 {
   51     /* FUNCTION process */
   52     int k;
   53 
   54     DEBUG printf("%d %lf  ", n, p);
   55     /*
   56        k^n = p
   57        log(k^n) = log(p)
   58        n * log(k) = log(p)
   59        log(k) = (log(p)) / n
   60        10^(log(k)) = 10^(log(p)/n)
   61     */
   62     k = pow(10, (log10(p) / n)) + 0.9;
   63     printf("%d\n", k);
   64 } /* FUNCTION process */
   65 
   66 int main ()
   67 {
   68     /* main */
   69     int moreToDo;
   70 
   71     init();
   72     moreToDo = getInput();
   73     while (moreToDo)
   74         {
   75             /* while */
   76             process();
   77             moreToDo = getInput();
   78         } /* while */
   79 
   80     return EXIT_SUCCESS;
   81 } /* main */
   82