#K79352. Maximum K-th Prime Factor Count in Subarrays

    ID: 35289 Type: Default 1000ms 256MiB

Maximum K-th Prime Factor Count in Subarrays

Maximum K-th Prime Factor Count in Subarrays

You are given an array of n integers and an integer k (1 ≤ k ≤ n). Your task is to consider all consecutive subarrays of length k, sort each subarray in increasing order, and then select the k-th element (i.e. the largest element in the sorted subarray). For each such chosen element x, define F(x) as the number of distinct prime factors of x (if x = 1, then F(x)=0). Your goal is to compute the maximum value of F(x) among all subarrays.

Mathematically, if we denote a subarray by \(A[i..i+k-1]\) and let \(B\) be the sorted version of the subarray, then you need to calculate:

[ \max_{0 \le i \le n-k} ; F(B[k-1]) ]

where \(F(x)\) is defined as:

[ F(x) = \text{number of distinct prime factors of } x ]

</p>

It is guaranteed that the input will always be such that a solution exists.

inputFormat

The first line of input contains two integers n and k separated by a space.

The second line contains n space-separated integers, representing the elements of the array.

Example:

5 3
10 15 21 24 30

outputFormat

Output a single integer which is the maximum value of the count of distinct prime factors (F(x)) for the k-th element in each sorted subarray.

Example:

3
## sample
5 3
10 15 21 24 30
3