Check if all the pairs of an array are coprime with each other | Python3 implementation of the above approach ; Function to check if all the pairs of the array are coprime with each other or not ; Check if GCD of the pair is not equal to 1 ; All pairs are non - coprime Return false ;  ; Driver code
def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT else : NEW_LINE INDENT return gcd ( b , a % b ) NEW_LINE DEDENT DEDENT def allCoprime ( A , n ) : NEW_LINE INDENT all_coprime = True NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if gcd ( A [ i ] , A [ j ] ) != 1 : NEW_LINE INDENT all_coprime = False ; NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return all_coprime NEW_LINE DEDENT / * Function return gcd of two number * / NEW_LINE if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 3 , 5 , 11 , 7 , 19 ] NEW_LINE arr_size = len ( A ) NEW_LINE if ( allCoprime ( A , arr_size ) ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT DEDENT