UberOA #1
Stable Transaction Periods
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesHashing
Given an array of non-negative integers, find the length of the longest non-empty contiguous subarray whose sum is divisible by k; output 0 if there is none.
This site's standard input/output is stated explicitly.
Input
The first line contains n k, and the second line contains n integers. 1≤n≤100000, 0≤a[i]≤10⁹, 1≤k≤10⁹.
Output
Output one integer answer.
Example 1
Input:
6 3
2 7 6 1 4 5
Output:
4
Example 2
Input:
1 2
1
Output:
0
Example 3
Input:
2 7
0 0
Output:
2
Example notes
Example 1: 7, 6, 1, 4 sum to 18, giving length 4; there is no longer valid range. Example 2: the only element 1 is not divisible by 2, so the output is 0. Example 3: the whole range sums to 0, which is divisible by 7, so the output is 2.
Editorial
Loading solution…