Computer Programming Contest Preparation

ToolBox - Source for: 126/12620/d.c



/home/toolbox/public_html/solutions/126/12620/d.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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2015-10-04
   20  * Purpose: fun
   21  * Problem: 12620
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define UPPER_LIMIT 300
   29 
   30 int numberOfTimes;
   31 int M;
   32 int N;
   33 unsigned char ans[UPPER_LIMIT];
   34 
   35 int fib(int a, int b)
   36 {
   37     /* FUNCTION fib */
   38 
   39     return ((a+b) % 100);
   40 } /* FUNCTION fib */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45     int i;
   46 
   47     for (i=0; i<UPPER_LIMIT; i++)
   48         {
   49             /* for i */
   50             if (0 == ans[i])
   51                 {
   52                     printf("%d ", i);
   53                 }
   54         } /* for i */
   55     printf("\n");
   56 } /* FUNCTION dump */
   57 
   58 void dump1()
   59 {
   60     /* FUNCTION dump1 */
   61     int i;
   62 
   63     for (i=0; i<100; i++)
   64         {
   65             /* for i */
   66             printf("%d: %d\n", i, ans[i]);
   67         } /* for i */
   68 } /* FUNCTION dump1 */
   69 
   70 void init()
   71 {
   72     /* FUNCTION init */
   73     int i;
   74 
   75     scanf("%d ", &numberOfTimes);
   76     ans[0] = 0;
   77     ans[1] = 1;
   78     ans[2] = 1;
   79     for (i=3; i<UPPER_LIMIT; i++)
   80         {
   81             /* for i */
   82             ans[i] = fib(ans[i-1], ans[i-2]);
   83             DEBUG printf("%d: %d\n", i, ans[i]);
   84             DEBUG dump();
   85         } /* for i */
   86     DEBUG dump1();
   87 } /* FUNCTION init */
   88 
   89 void getInput()
   90 {
   91     /* FUNCTION getInput */
   92     scanf(" %d %d ", &M, &N);
   93 } /* FUNCTION getInput */
   94 
   95 unsigned long long sum(int m, int n)
   96 {
   97     /* FUNCTION sum */
   98     int i;
   99     unsigned long long tot = 0;
  100 
  101     for (i=m; i<=n; i++)
  102         {
  103             /* for i */
  104             tot = tot + ans[i % 300];
  105         } /* for i */
  106     return tot;
  107 } /* FUNCTION sum */
  108 
  109 void process()
  110 {
  111     /* FUNCTION process */
  112     int i;
  113     int m;
  114     int n;
  115     unsigned long long tot = 0;
  116 
  117 
  118     if ((300 > m) && (300 <= N))
  119         {
  120             /* split case */
  121             tot = sum(M, 299) + sum(300, N);
  122         } /* split case */
  123     else
  124         {
  125             /* normal */
  126             tot = sum(M, N);
  127         } /* normal */
  128     printf("%Ld\n", tot);
  129 
  130 } /* FUNCTION process */
  131 
  132 int main()
  133 {
  134     /* main */
  135     int i;
  136 
  137     init();
  138     for (i=0; i<numberOfTimes; i++)
  139         {
  140             /* while */
  141             getInput();
  142             process();
  143         } /* while */
  144 
  145     return EXIT_SUCCESS;
  146 } /* main */
  147 
  148