Partitions possible such that the minimum element divides all the other elements of the partition | Javascript implementation of the approach ; Function to return the count partitions possible from the given array such that the minimum element of any partition divides all the other elements of that partition ; Initialize the count variable ; Find the minimum element ; Break if no minimum element present ; Increment the count if minimum element present ; Replace all the element divisible by min_elem ; Driver code
var INT_MAX = 1000000000 ; function min_element ( A , N ) { var min = A [ 0 ] ; var i ; for ( i = 1 ; i < N ; i ++ ) { if ( min > A [ i ] ) { min = A [ i ] ; } } return min ; } function countPartitions ( A , N ) { var count = 0 ; var i , j ; for ( i = 0 ; i < N ; i ++ ) { var min_elem = min_element ( A , N ) ; if ( min_elem == INT_MAX ) break ; count ++ ; for ( j = 0 ; j < N ; j ++ ) { if ( A [ j ] % min_elem == 0 ) A [ j ] = INT_MAX ; } } return count ; } var arr = [ 7 , 6 , 5 , 4 , 3 , 2 , 2 , 3 ] ; var N = arr . length ; document . write ( countPartitions ( arr , N ) ) ;