Count of elements on the left which are divisible by current element | Utility function to print the elements of the array ; Function to generate and print the required array ; For every element of the array ; To store the count of elements on the left that the current element divides ; Print the generated array ; Driver code
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function generateArr ( A , n ) { let B = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let cnt = 0 ; for ( let j = 0 ; j < i ; j ++ ) { if ( A [ j ] % A [ i ] == 0 ) cnt ++ ; } B [ i ] = cnt ; } printArr ( B , n ) ; } let A = [ 3 , 5 , 1 ] ; let n = A . length ; generateArr ( A , n ) ;