Minimum LCM of all pairs in a given array | Python3 program to find minimum possible lcm from any pair ; Function to compute GCD of two numbers ; Function that return minimum possible lcm from any pair ; Fix the ith element and iterate over all the array to find minimum LCM ; Driver code
import sys NEW_LINE def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT return gcd ( b , a % b ) ; NEW_LINE DEDENT def minLCM ( arr , n ) : NEW_LINE INDENT ans = 1000000000 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT g = gcd ( arr [ i ] , arr [ j ] ) ; NEW_LINE lcm = arr [ i ] / g * arr [ j ] ; NEW_LINE ans = min ( ans , lcm ) ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT arr = [ 2 , 4 , 3 , 6 , 5 ] ; NEW_LINE print ( minLCM ( arr , 5 ) ) NEW_LINE