We’re preparing your current view and syncing the latest data.
You are given an array of integers nums and an integer k. A prefix subarray is defined as any subarray that starts from index 0 and extends to some index i (0 <= i < nums.length). Your task is to count how many prefix subarrays have a sum that when taken modulo k equals a specified residue value r.
Print a single integer representing the count of prefix subarrays where (sum of elements) mod k equals r.
Example 1
Input
5 3 1 2 3 4 1 0
Output
2
Explanation
Prefix sums modulo 3 are: [1, 0, 0, 1, 2]. Prefixes with modulo 0 are at indices 1 and 2, so count is 2.