#C6076. Longest Divisible Subarray
Longest Divisible Subarray
Longest Divisible Subarray
Given an array of integers and a divisor \( k \), your task is to find the length of the longest contiguous subarray whose sum is divisible by \( k \). More formally, for an array \( arr \) of size \( n \), find the maximum value of \( length \) such that there exists indices \( i \) and \( j \) with \( 0 \leq i \leq j < n \) for which
\( \sum_{l=i}^{j} arr[l] \equiv 0 \pmod{k} \)
If no such subarray exists, you should return 0.
The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).
inputFormat
The first line contains two integers \( n \) and \( k \), where \( n \) is the number of elements in the array and \( k \) is the divisor.
The second line contains \( n \) space-separated integers representing the array \( arr \).
outputFormat
Output a single integer which is the length of the longest contiguous subarray whose sum is divisible by \( k \). If no such subarray exists, output 0.
## sample6 3
2 7 6 1 4 5
4