#C5993. Taco Checksum
Taco Checksum
Taco Checksum
You are given multiple datasets. Each dataset consists of two lines:
- The first line contains two integers \(N\) and \(M\), where \(N\) is the number of elements in the array and \(M\) is the modulo divisor.
- The second line contains \(N\) space-separated integers representing the array \(A\).
The input terminates when a dataset with \(N = 0\) and \(M = 0\) is encountered; this dataset should not be processed. For each valid dataset, compute the checksum defined as
\[ \text{checksum} = \left( \sum_{i=1}^{N} A_i \right) \bmod M \]
Output the checksum for each dataset on a separate line.
inputFormat
The input is read from standard input (stdin). It consists of multiple datasets. Each dataset is described in two lines:
-
The first line contains two integers N and M separated by a space. N represents the number of integers in the array A and M is the divisor for modulo operation. A dataset with N = 0 and M = 0 marks the end of input and should not be processed.
-
The second line contains N space-separated integers, representing the array A.
For example:
5 3 1 2 3 4 5 0 0
outputFormat
For each dataset (except the terminating dataset), output the computed checksum on a separate line. The checksum is defined as the sum of the elements of the array modulo M.## sample
5 3
1 2 3 4 5
0 0
0
</p>