Count of elements on the left which are divisible by current element | Set 2 | Utility function to prthe elements of the array ; Function to increment the count for each factor of given val ; Function to generate and print the required array ; Find max element of arr ; Create count array of maxi size ; For every element of the array ; Count [ A [ i ] ] denotes how many previous elements are there whose factor is the current element . ; Increment in count array for factors of A [ i ] ; Print the generated array ; Driver code
def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def IncrementFactors ( count , val ) : NEW_LINE INDENT i = 1 NEW_LINE while ( i * i <= val ) : NEW_LINE INDENT if ( val % i == 0 ) : NEW_LINE INDENT if ( i == val // i ) : NEW_LINE INDENT count [ i ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count [ i ] += 1 NEW_LINE count [ val // i ] += 1 NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT DEDENT def generateArr ( A , n ) : NEW_LINE INDENT B = [ 0 ] * n NEW_LINE maxi = max ( A ) NEW_LINE count = [ 0 ] * ( maxi + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT B [ i ] = count [ A [ i ] ] NEW_LINE IncrementFactors ( count , A [ i ] ) NEW_LINE DEDENT printArr ( B , n ) NEW_LINE DEDENT arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE generateArr ( arr , n ) NEW_LINE