Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/126/12620/c.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 int numberOfTimes;
   29 int M;
   30 int N;
   31 int ans[100];
   32 
   33 int fib(int a, int b)
   34 {
   35     /* FUNCTION fib */
   36 
   37     return ((a+b) % 100);
   38 } /* FUNCTION fib */
   39 
   40 void dump()
   41 {
   42     /* FUNCTION dump */
   43     int i;
   44 
   45     for (i=0; i<100; i++)
   46         {
   47             /* for i */
   48             if (0 == ans[i])
   49                 {
   50                     printf("%d ", i);
   51                 }
   52         } /* for i */
   53     printf("\n");
   54 } /* FUNCTION dump */
   55 
   56 void dump1()
   57 {
   58     /* FUNCTION dump1 */
   59     int i;
   60 
   61     for (i=0; i<100; i++)
   62         {
   63             /* for i */
   64             printf("%d: %d\n", i, ans[i]);
   65         } /* for i */
   66 } /* FUNCTION dump1 */
   67 
   68 void init()
   69 {
   70     /* FUNCTION init */
   71     int i;
   72 
   73     scanf("%d ", &numberOfTimes);
   74     ans[1] = 1;
   75     ans[2] = 1;
   76     for (i=3; i<100; i++)
   77         {
   78             /* for i */
   79             ans[i] = fib(ans[i-1], ans[i-2]);
   80             DEBUG printf("%d: ", i);
   81             DEBUG dump();
   82         } /* for i */
   83     ans[0] = fib(ans[98], ans[99]);
   84     DEBUG dump1();
   85 } /* FUNCTION init */
   86 
   87 void getInput()
   88 {
   89     /* FUNCTION getInput */
   90     scanf(" %d %d ", &M, &N);
   91 } /* FUNCTION getInput */
   92 
   93 unsigned long long sum(int m, int n)
   94 {
   95     /* FUNCTION sum */
   96     int i;
   97     unsigned long long tot = 0;
   98 
   99     for (i=m; i<=n; i++)
  100         {
  101             /* for i */
  102             tot = tot + ans[i % 100];
  103         } /* for i */
  104     return tot;
  105 } /* FUNCTION sum */
  106 
  107 void process()
  108 {
  109     /* FUNCTION process */
  110     int i;
  111     int m;
  112     int n;
  113     unsigned long long tot = 0;
  114 
  115     tot = sum(M, N);
  116     printf("%Ld\n", tot);
  117 
  118 } /* FUNCTION process */
  119 
  120 int main()
  121 {
  122     /* main */
  123     int i;
  124 
  125     init();
  126     for (i=0; i<numberOfTimes; i++)
  127         {
  128             /* while */
  129             getInput();
  130             process();
  131         } /* while */
  132 
  133     return EXIT_SUCCESS;
  134 } /* main */
  135 
  136