Find the count of subsequences where each element is divisible by K | Function to return the count of all valid subsequences ; To store the count of elements which are divisible by k ; If current element is divisible by k then increment the count ; Total ( 2 ^ n - 1 ) non - empty subsequences are possible with n element ; Driver code
function countSubSeq ( arr , n , k ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { count ++ ; } } return ( Math . pow ( 2 , count ) - 1 ) ; } let arr = [ 1 , 2 , 3 , 6 ] ; let n = arr . length ; let k = 3 ; document . write ( countSubSeq ( arr , n , k ) ) ;