LCM of given array elements | Recursive function to return gcd of a and b ; recursive implementation ; lcm ( a , b ) = ( a * b / gcd ( a , b ) ) ; Driver code
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 LcmOfArray ( arr , idx ) : NEW_LINE INDENT if ( idx == len ( arr ) - 1 ) : NEW_LINE INDENT return arr [ idx ] NEW_LINE DEDENT a = arr [ idx ] NEW_LINE b = LcmOfArray ( arr , idx + 1 ) NEW_LINE return int ( a * b / __gcd ( a , b ) ) NEW_LINE DEDENT arr = [ 1 , 2 , 8 , 3 ] NEW_LINE print ( LcmOfArray ( arr , 0 ) ) NEW_LINE arr = [ 2 , 7 , 3 , 9 , 4 ] NEW_LINE print ( LcmOfArray ( arr , 0 ) ) NEW_LINE