text: Modify array such that the array does not contain any common divisors other than 1 | Python3 program for the above approach ; Function to check if it is possible to modify the array such that there is no common factor between array elements except 1 ; Stores GCD of the array ; Calculate GCD of the array ; If the current divisor is smaller than X ; Divide GCD by the current divisor ; If possible ; Print the modified array ; Otherwise ; Driver Code ; Given array ; Size of the array
code: import math NEW_LINE def checkCommonDivisor ( arr , N , X ) : NEW_LINE INDENT G = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT G = math . gcd ( G , arr [ i ] ) NEW_LINE DEDENT copy_G = G NEW_LINE for divisor in range ( 2 , X + 1 ) : NEW_LINE INDENT while ( G % divisor == 0 ) : NEW_LINE INDENT G = G // divisor NEW_LINE DEDENT DEDENT if ( G <= X ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT print ( arr [ i ] // copy_G , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 6 , 15 , 6 ] NEW_LINE X = 6 NEW_LINE N = len ( arr ) NEW_LINE checkCommonDivisor ( arr , N , X ) NEW_LINE DEDENT