Count all subsequences having product less than K | Function to count numbers of such subsequences having product less than k . ; number of subsequence using j - 1 terms ; if arr [ j - 1 ] > i it will surely make product greater thus it won 't contribute  then ; number of subsequence using 1 to j - 1 terms and j - th term ; Driver code
function productSubSeqCount ( arr , k ) { let n = arr . length ; let dp = new Array ( k + 1 ) ; for ( let i = 0 ; i < k + 1 ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= k ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ; if ( arr [ j - 1 ] <= i && arr [ j - 1 ] > 0 ) dp [ i ] [ j ] += dp [ parseInt ( i / arr [ j - 1 ] , 10 ) ] [ j - 1 ] + 1 ; } } return dp [ k ] [ n ] ; } let A = [ 1 , 2 , 3 , 4 ] ; let k = 10 ; document . write ( productSubSeqCount ( A , k ) ) ;