Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/1/138/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: Isaac Traxler
   17  *    Date: 2015-10-18
   18  * Purpose: fun
   19  * Problem: 138
   20  */
   21 
   22 #define NUMBER_TYPE unsigned long long int
   23 
   24 
   25 int main()
   26 {
   27     /* main */
   28     int i = 0;
   29     long houseNumber = 1;
   30     long houses;
   31     NUMBER_TYPE preTot = 0;
   32     NUMBER_TYPE postTot = 0;
   33     long houseCnt = 1;
   34 
   35     while (10 > i)
   36         {
   37             /* while more solutions to do */
   38             houseCnt++;
   39             postTot = postTot + houseCnt;
   40             while (postTot < preTot)
   41                 {
   42                     /* while houses after not enough */
   43                     houseCnt++;
   44                     postTot = postTot + houseCnt;
   45                 } /* while houses after not enough */
   46             if (preTot == postTot)
   47                 {
   48                     /* found an answer */
   49                     printf("%10d%10d\n", houseNumber, houseCnt);
   50                     i++;
   51                 } /* found an answer */
   52             preTot = preTot + houseNumber;
   53             houseNumber++;
   54             postTot = postTot - houseNumber;
   55         } /* while more solutions to do */
   56 
   57 
   58     return EXIT_SUCCESS;
   59 } /* main */
   60