#C9721. Longest Subarray with All Elements Divisible by K
Longest Subarray with All Elements Divisible by K
Longest Subarray with All Elements Divisible by K
Given an array of n integers and an integer k, your task is to determine the length of the longest contiguous subarray where every element is divisible by k. In other words, find the maximum length L such that there exists a subarray of consecutive elements of the given array where each element satisfies the condition \(a_i \mod k = 0\).
Note: The subarray must be contiguous, meaning the elements appear consecutively).
inputFormat
The input is read from standard input. 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.
outputFormat
Output a single integer — the length of the longest contiguous subarray in which every element is divisible by k.## sample
8 3
3 6 9 2 18 21 4 12
3