#C3874. Maximum Subarray Length Divisible by Primes
Maximum Subarray Length Divisible by Primes
Maximum Subarray Length Divisible by Primes
You are given an array A of n integers and two integers m and p specifying a range of numbers. Consider all prime numbers \(p_i\) such that \(m \leq p_i \leq p\). A subarray of A is considered valid if for every element in the subarray there exists at least one prime \(p_i\) which divides that element (i.e. the element modulo \(p_i\) is zero). Your task is to find the maximum length of a contiguous subarray that is valid.
To achieve this, you may first generate all primes in the range \([m, p]\) using the Sieve of Eratosthenes algorithm. Then, for each test case, scan through the array and keep track of the lengths of valid contiguous segments.
If no valid subarray exists, output 0.
inputFormat
The first line contains a single integer t representing the number of test cases.
For each test case, the first line contains three space-separated integers: n (the number of elements in the array), m, and p (the bounds of the prime range).
The next line contains n space-separated integers representing the array A.
outputFormat
For each test case, output a single line with the maximum length of a contiguous subarray in which every element is divisible by at least one prime in the range \([m, p]\).
## sample6
6 2 5
6 10 15 20 25 30
5 3 7
14 21 28 35 42
4 4 4
1 1 1 1
1 2 5
10
4 2 3
5 7 11 13
5 2 7
2 3 5 7 14
6
5
0
1
0
5
</p>