Minimum number of cuts required to make circle segments equal sized | Recursive function to return gcd of two nos ; Function to find the minimum number of additional cuts required to make circle segments are equal sized ; Sort the array ; Initial gcd value ; Including the last segment ; Driver Code
< ? php function findgcd ( $ a , $ b ) { if ( $ b == 0 ) return $ a ; return findgcd ( $ b , $ a % $ b ) ; } function minimumCuts ( $ a , $ n ) { sort ( $ a ) ; $ gcd = $ a [ 1 ] - $ a [ 0 ] ; $ s = $ gcd ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) { $ gcd = findgcd ( $ gcd , $ a [ $ i ] - $ a [ $ i - 1 ] ) ; $ s += $ a [ $ i ] - $ a [ $ i - 1 ] ; } if ( 360 - $ s > 0 ) $ gcd = findgcd ( $ gcd , 360 - $ s ) ; return ( 360 / $ gcd ) - $ n ; } $ arr = array ( 30 , 60 , 180 ) ; $ n = sizeof ( $ arr ) ; echo ( minimumCuts ( $ arr , $ n ) ) ; ? >