Common divisors of N numbers | Function to calculate gcd of two numbers ; Function to prall the common divisors ; Variable to find the gcd of N numbers ; Set to store all the common divisors ; Finding GCD of the given N numbers ; Finding divisors of the HCF of n numbers ; Prall the divisors ; Driver 's Code ; Function to prall the common divisors
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 printAllDivisors ( arr , N ) : NEW_LINE INDENT g = arr [ 0 ] NEW_LINE divisors = dict ( ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT g = gcd ( arr [ i ] , g ) NEW_LINE DEDENT for i in range ( 1 , g + 1 ) : NEW_LINE INDENT if i * i > g : NEW_LINE INDENT break NEW_LINE DEDENT if ( g % i == 0 ) : NEW_LINE INDENT divisors [ i ] = 1 NEW_LINE if ( g // i != i ) : NEW_LINE INDENT divisors [ g // i ] = 1 NEW_LINE DEDENT DEDENT DEDENT for it in sorted ( divisors ) : NEW_LINE INDENT print ( it , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 6 , 90 , 12 , 18 , 30 , 24 ] NEW_LINE n = len ( arr ) NEW_LINE printAllDivisors ( arr , n ) NEW_LINE DEDENT