Minimum number of cuts required to make circle segments equal sized | Java program to find the minimum number of additional 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
import java . util . Arrays ; class GFG { static int findgcd ( int a , int b ) { if ( b == 0 ) return a ; return findgcd ( b , a % b ) ; } static int minimumCuts ( int a [ ] , int n ) { Arrays . sort ( a ) ; int gcd = a [ 1 ] - a [ 0 ] ; int s = gcd ; for ( int 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 ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 30 , 60 , 180 } ; int n = arr . length ; System . out . println ( minimumCuts ( arr , n ) ) ; } }