Count pairs in an array whose product is composite number | Function to check if a number is prime or not ; Check if N is multiple of i or not . ; If N is multiple of i . ; Function to get the count of pairs whose product is a composite number . ; Stores the count of pairs whose product is a composite number ; Generate all possible pairs ; Stores the product of element of current pair ; If prod is a composite number ; Driver Code
def isComposite ( N ) : NEW_LINE INDENT for i in range ( 2 , N + 1 ) : NEW_LINE INDENT if i * i > N : NEW_LINE INDENT break NEW_LINE DEDENT if ( N % i == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def compositePair ( arr , N ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT prod = arr [ i ] * arr [ j ] NEW_LINE if ( isComposite ( prod ) ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 2 , 2 , 8 ] NEW_LINE N = len ( arr ) NEW_LINE print ( compositePair ( arr , N ) ) NEW_LINE DEDENT