UberOA #1
Stable Transaction Periods
估计中等可在线判题
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.
输入格式
The first line contains n k, and the second line contains n integers. 1≤n≤100000, 0≤a[i]≤10⁹, 1≤k≤10⁹.
输出格式
Output one integer answer.
样例 1
输入:
6 3
2 7 6 1 4 5
输出:
4
样例 2
输入:
1 2
1
输出:
0
样例 3
输入:
2 7
0 0
输出:
2
样例说明
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.