#C4169. Unique K-Length Subarrays with Divisible Sum

    ID: 47677 Type: Default 1000ms 256MiB

Unique K-Length Subarrays with Divisible Sum

Unique K-Length Subarrays with Divisible Sum

Given an array of integers and an integer k, your task is to count the number of contiguous subarrays of length k whose sum is divisible by k. In other words, for each contiguous subarray [a_i, a_{i+1}, \dots, a_{i+k-1}], count it if and only if:

\( \sum_{j=0}^{k-1} a_{i+j} \equiv 0 \; (\mathrm{mod} \; k) \)

This is a straightforward implementation problem that tests your ability to correctly iterate over subarrays and check divisibility conditions.

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains a single integer n, the number of elements in the array.
  • The second line contains n space-separated integers representing the elements of the array.
  • The third line contains a single integer k.

outputFormat

Output via standard output (stdout) a single integer — the count of contiguous subarrays of length k whose sum is divisible by k.

## sample
5
2 4 6 8 10
2
4