422. Subarray Sums Divisible by K
MediumPrefix SumModulo
Count the non-empty contiguous subarrays whose sum is divisible by k.
Input format
Line 1: n k Line 2: n integers
Output format
The count.
Example 1
Input
6 5 4 5 0 -2 -3 1
Output
7
Example 2
Input
1 9 5
Output
0
Constraints
1 ≤ n ≤ 10⁵ 2 ≤ k ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…