Computer Programming Contest Preparation

ToolBox - Source for: 103/10346/b.c



/home/toolbox/public_html/solutions/103/10346/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 #define MAX_LINE 257
   16 
   17 /*
   18  *  Author:
   19  *    Date:
   20  * Purpose:
   21  * Problem:
   22  */
   23 
   24 /*
   25  * This template reads lines of data at a time until end of file.
   26  */
   27 
   28 int n;
   29 int k;
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45 
   46     dataReadFlag = 0 <= scanf(" %d %d ", &n, &k);
   47     return (dataReadFlag);
   48 } /* FUNCTION getInput */
   49 
   50 void process()
   51 {
   52     /* FUNCTION process */
   53     int tot;
   54     int left;
   55 
   56     tot = n + (n / k);
   57     left = (n / k) + (n % k);
   58     while (k <= left)
   59         {
   60             /* while */
   61             tot = tot + (left / k);
   62             left = (left % k) + (left / k);
   63         } /* while */
   64     left = n + (n-1)/(k-1);
   65     printf("%d %d\n", tot, left);
   66 
   67 } /* FUNCTION process */
   68 
   69 int main()
   70 {
   71     /* main */
   72     int moreToDo;
   73 
   74     init();
   75     moreToDo = getInput();
   76     while (moreToDo)
   77         {
   78             /* while */
   79             process();
   80             moreToDo = getInput();
   81         } /* while */
   82 
   83     return EXIT_SUCCESS;
   84 } /* main */
   85