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
function findgcd ( a , b ) { if ( b == 0 ) return a ; return findgcd ( b , a % b ) ; } function minimumCuts ( a , n ) { a . sort ( ) ; var gcd = a [ 1 ] - a [ 0 ] ; var 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 ; } var arr = [ 30 , 60 , 180 ] ; var n = arr . length ; document . write ( minimumCuts ( arr , n ) ) ;