/home/toolbox/public_html/solutions/104/10489/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 <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: 2020-03-03
20 * Purpose: fun
21 * Problem: 10489 - Boxes od chocolates
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 int numberOfTimes;
29 int tot; /* how many chocolatess go to the cat */
30 int n; /* number of friends */
31 int t; /* number of test cases */
32 int b; /* number of boxes */
33 int k; /* number of chocolates in last box */
34
35 void init()
36 {
37 /* FUNCTION init */
38 scanf("%d ", &numberOfTimes);
39 } /* FUNCTION init */
40
41 void dump()
42 {
43 /* FUNCTION dump */
44 } /* FUNCTION dump */
45
46 void getInput()
47 {
48 /* FUNCTION getInput */
49 int tmp;
50 int box;
51 int i;
52 int j;
53
54 tot = 0;
55 scanf(" %d %d ", &n, &b);
56 for (i=0; b>i; i++)
57 {
58 /* loop for each outer box */
59 scanf(" %d ", &k); /* get number of sub boxes */
60 tmp = 1;
61 for (j=0; k>j; j++)
62 {
63 /* for each contained box */
64 scanf(" %d ", &box);
65 tmp = (tmp * box) % n;
66 } /* for each contained box */
67 tot = (tot + tmp) % n;
68 } /* loop for each outer box */
69 tot = tot % n;
70 } /* FUNCTION getInput */
71
72 void process()
73 {
74 /* FUNCTION process */
75 printf("%d\n", tot);
76 } /* FUNCTION process */
77
78 int main()
79 {
80 /* main */
81 int i;
82
83 init();
84 for (i=0; i<numberOfTimes; i++)
85 {
86 /* while */
87 getInput();
88 process();
89 } /* while */
90
91 return EXIT_SUCCESS;
92 } /* main */
93
94