22820_DivisibleSubsequences

2022-5-16 18:23| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506988501100-Problem List-采集的数据-后羿采集器.html

Pro.ID

22820

Title

Divisible Subsequences

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22820

AC

21

Submit

69

Ratio

30.43%

时间&空间限制

  • Time Limit: 10000/5000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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 ≤ 1000000 ) and n ( 1 ≤ n ≤ 50000 ), 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 1000000000, inclusively.

    输出

    Description

    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.

    Input

    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 ≤ 1000000 ) and n ( 1 ≤ n ≤ 50000 ), 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 1000000000, inclusively.

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

    Sample Input

    2
    7 3
    1 2 3
    4 8
    2 1 2 1 1 2 1 2

    Sample Output

    0
    6

    Source

    样例输入

    2
    7 3
    1 2 3
    4 8
    2 1 2 1 1 2 1 2

    样例输出

    0
    6

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部