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 leto N equals parts and each part can be further divided leto arr [ i ] equal parts ; Prlet the result ; Driver Code
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function findlcm ( arr , n ) { let ans = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) ) ; } return ans ; } function minimumRod ( A , N ) { document . write ( N * findlcm ( A , N ) ) ; } let arr = [ 1 , 2 ] ; let N = arr . length ; minimumRod ( arr , N ) ;