Problem BH
Divisible Subsequences
Given a sequence of positive integers, count all contiguous subsequences (sometimes called substrings, in contrast to subsequences, which may leave out elements) the sum of which is divisible by a given number. These subsequences may overlap. For example, the sequence (see sample input)
contains six contiguous subsequences the sum of which is divisible by four: the first to eighth number, the second to fourth number, the second to seventh number, the third to fifth number, the fourth to sixth number, and the fifth to seventh number.
Input
The first line of the input consists of an integer
Each test case starts with a line consisting of two integers
Output
For each test case, print a single line consisting of a
single integer, the number of contiguous subsequences the sum
of which is divisible by
Sample Input 1 | Sample Output 1 |
---|---|
2 7 3 1 2 3 4 8 2 1 2 1 1 2 1 2 |
0 6 |