Remainder Subarray Count
InterviewTime limit1sMemory limit256 MB
Count contiguous intervals whose sum is divisible by M using prefix remainder frequencies.
- Level
Medium4 of 10
- Topics
- Prefix sum, Hash map
- Solved
- No attempts yet
Problem
You are given a sequence of length . Count the contiguous intervals whose sum is divisible by .
An interval is a pair with , and it covers through . Two intervals count as different when they differ in or in .
Input
The first line contains and , separated by a space. (, )
The second line contains the numbers of the sequence , separated by spaces. ()
Output
Print the number of intervals that satisfy the condition on the first line.