text: Minimum LCM and GCD possible among all possible sub | Function to return minimum GCD among all subarrays ; Minimum GCD among all sub - arrays will be the GCD of all the elements of the array ; Function to return minimum LCM among all subarrays ; Minimum LCM among all sub - arrays will be the minimum element from the array ; Driver code
code: < ? php function __gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return __gcd ( $ b % $ a , $ a ) ; } function minGCD ( $ arr , $ n ) { $ minGCD = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ minGCD = __gcd ( $ minGCD , $ arr [ $ i ] ) ; return $ minGCD ; } function minLCM ( $ arr , $ n ) { $ minLCM = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ minLCM = min ( $ minLCM , $ arr [ $ i ] ) ; return $ minLCM ; } $ arr = array ( 2 , 66 , 14 , 521 ) ; $ n = sizeof ( $ arr ) ; echo " LCM = " ▁ . ▁ minLCM ( $ arr , ▁ $ n ) ▁ . ▁ " , " echo " GCD ▁ = ▁ " . minGCD ( $ arr , $ n ) ; ? >