Given an array arr[]
of n
numbers and an integer k
, find length of the minimum sub-array with gcd equals to k
.
Example:
Input: arr[] = {6, 9, 7, 10, 12, 24, 36, 27}
, k = 3
Output: 2
Explanation: GCD of subarray {6,9} is 3. GCD of subarray {24,36,27} is also 3, but {6,9} is the smallest
There's a better algorithm using segment tree.