Minimum number of cuts required to make circle segments equal sized | CPP program to find the minimum number of additional cuts required to make circle segments equal sized ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumCuts ( int a [ ] , int n ) { sort ( a , a + n ) ; int gcd = a [ 1 ] - a [ 0 ] ; int s = gcd ; for ( int i = 2 ; i < n ; i ++ ) { gcd = __gcd ( gcd , a [ i ] - a [ i - 1 ] ) ; s += a [ i ] - a [ i - 1 ] ; } if ( 360 - s > 0 ) gcd = __gcd ( gcd , 360 - s ) ; return ( 360 / gcd ) - n ; } int main ( ) { int arr [ ] = { 30 , 60 , 180 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimumCuts ( arr , n ) ; return 0 ; }