Computer Programming Contest Preparation

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



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