Split the array

Правка en2, от Saitama_27, 2020-08-29 18:39:18

There is an array "val" of n integers. A good subarray is defined as: A subarray val[i to j] is 'good subarray' if gcd(val[i],val[j])>1 (where 0<=i<=j<n).

Task is to split the whole array in such a way that each split subarray is good and one of each element in the array val belongs to exactly one subarray. Calculate the minimum number of splits with each subarray being a 'good subarray'.

Note: gcd(a,b) is greatest commmon divisor of two numbers.

I thought of applying dp but constraints are high. Can anyone help with better approach.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Saitama_27 2020-08-29 18:39:18 4 Tiny change: 'd and one val of each e' -> 'd and one of each e'
en1 Английский Saitama_27 2020-08-29 18:38:21 574 Initial revision (published)