Minimum length of a rod that can be split into N equal parts that can further be split into given number of equal parts | Function to find GCD of two numbers a and b ; Base Case ; Find GCD recursively ; Function to find the LCM of the resultant array ; Initialize a variable ans as the first element ; Traverse the array ; Update LCM ; Return the minimum length of the rod ; Function to find the minimum length of the rod that can be divided into N equals parts and each part can be further divided into arr [ i ] equal parts ; Print the result ; Driver Code
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 findlcm ( arr , n ) : NEW_LINE INDENT ans = arr [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT def minimumRod ( A , N ) : NEW_LINE INDENT print ( int ( N * findlcm ( A , N ) ) ) NEW_LINE DEDENT arr = [ 1 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE minimumRod ( arr , N ) NEW_LINE