Check if all array elements are pairwise co | Function to calculate GCD ; Function to calculate LCM ; Function to check if aelements in the array are pairwise coprime ; Initialize variables ; Iterate over the array ; Calculate product of array elements ; Calculate LCM of array elements ; If the product of array elements is equal to LCM of the array ; Driver Code ; Function call
def GCD ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return GCD ( b % a , a ) NEW_LINE DEDENT def LCM ( a , b ) : NEW_LINE INDENT return ( a * b ) // GCD ( a , b ) NEW_LINE DEDENT def checkPairwiseCoPrime ( A , n ) : NEW_LINE INDENT prod = 1 NEW_LINE lcm = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT prod *= A [ i ] NEW_LINE lcm = LCM ( A [ i ] , lcm ) NEW_LINE DEDENT if ( prod == lcm ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 2 , 3 , 5 ] NEW_LINE n = len ( A ) NEW_LINE checkPairwiseCoPrime ( A , n ) NEW_LINE DEDENT