这是一道英文题,欢迎大家尝试。
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≤l≤r≤N.
- 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 |
Givenarowofboxeswithcandies,findthenumberofpairs(l,r)wherethesumofcandiesinboxesfromltorisamultipleofM,anddistributethemevenlyamongMchildren.
304

被折叠的 条评论
为什么被折叠?



