2774. Divisible Subsequences

单点时限: 5.0 sec

内存限制: 256 MB

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)

2, 1, 2, 1, 1, 2, 1, 2

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.

输入格式

The first line of the input consists of an integer c (1 <= c <= 200), the number of test cases. Then follow two lines per test case.

Each test case starts with a line consisting of two integers d (1 <= d <= 1 000 000) and n (1 <= n <= 50 000), the divisor of the sum of the subsequences and the length of the sequence, respectively. The second line of a test case contains the elements of the sequence, which are integers between 1 and 1 000 000 000, inclusively.

输出格式

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 d.

样例

Input
2
7 3
1 2 3
4 8
2 1 2 1 1 2 1 2
Output
0
6

19 人解决,38 人已尝试。

42 份提交通过,共有 179 份提交。

6.0 EMB 奖励。

创建: 12 年,10 月前.

修改: 5 年,1 月前.

最后提交: 4 年,6 月前.

来源: NWERC 2009

题目标签