【分糖果】

Givenarowofboxeswithcandies,findthenumberofpairs(l,r)wherethesumofcandiesinboxesfromltorisamultipleofM,anddistributethemevenlyamongMchildren.

这是一道英文题,欢迎大家尝试。

Problem Statement

There are NN boxes arranged in a row from left to right. The ii-th box from the left contains A_iAi candies.

You will take out the candies from some consecutive boxes and distribute them evenly to MM children.

Such being the case, find the number of the pairs (l, r)(l,r) that satisfy the following:

  • ll and rr are both integers and satisfy 1 \leq l \leq r \leq N1≤lrN.
  • A_l + A_{l+1} + ... + A_rAl+Al+1+...+Ar is a multiple of MM.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^51≤N≤105
  • 2 \leq M \leq 10^92≤M≤109
  • 1 \leq A_i \leq 10^91≤Ai≤109

Input

Input is given from Standard Input in the following format:

NN MMA_1A1 A_2A2 ...... A_NAN

Output

Print the number of the pairs (l, r)(l,r) that satisfy the conditions.

Note that the number may not fit into a 3232-bit integer type.

Sample 1

Inputcopy

Outputcopy

3 2

4 1 5

3

The sum A_l + A_{l+1} + ... + A_rAl+Al+1+...+Ar for each pair (l, r)(l,r) is as follows:

  • Sum for (1, 1)(1,1)44
  • Sum for (1, 2)(1,2)55
  • Sum for (1, 3)(1,3)1010
  • Sum for (2, 2)(2,2)11
  • Sum for (2, 3)(2,3)66
  • Sum for (3, 3)(3,3)55

Among these, three are multiples of 22.

Sample 2

Inputcopy

Outputcopy

13 17

29 7 5 7 9 51 7 13 8 55 42 9 81

6

Sample 3

Inputcopy

Outputcopy

10 400000000

1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

25

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值