# Minimum number of cuts required to make circle segments equal sized

Given an array of elements where each element in the array represents the degree ( 0 <= a[i] <= 359 ) at which there is already a cut in a circle. The task is to find the minimum number of additional cuts required to make circle segments equal sized.

Examples:

```Input : arr[] = { 0, 2 }
Output : 178

Input : arr[] = { 30, 60, 180 }
Output : 9
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach : An efficient way to solve the above problem is to find gcd of all consecutive difference in angles. This gcd is the maximum angle of one circular segment and then the number of segments will be 360/gcdObtained. But, there are already N cuts. so additional cuts will be (360/gcdObtained) – N.

Below is the implementation of the above approach:

## C++

 `// CPP program to find the minimum number ` `// of additional cuts required to make ` `// circle segments equal sized ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to find the minimum number ` `// of additional cuts required to make ` `// circle segments are equal sized ` `int` `minimumCuts(``int` `a[], ``int` `n) ` `{ ` `    ``// Sort the array ` `    ``sort(a, a + n); ` ` `  `    ``// Initial gcd value ` `    ``int` `gcd = a - a; ` `    ``int` `s = gcd; ` ` `  `    ``for` `(``int` `i = 2; i < n; i++) { ` `        ``gcd = __gcd(gcd, a[i] - a[i - 1]); ` `        ``s += a[i] - a[i - 1]; ` `    ``} ` ` `  `    ``// Inlcuding the last segment ` `    ``if` `(360 - s > 0) ` `        ``gcd = __gcd(gcd, 360 - s); ` ` `  `    ``return` `(360 / gcd) - n; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `arr[] = { 30, 60, 180 }; ` ` `  `    ``int` `n = ``sizeof``(arr) / ``sizeof``(arr); ` ` `  `    ``cout << minimumCuts(arr, n); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java program to find the minimum  ` `// number of additional cuts required ` `// to make circle segments equal sized ` `import` `java.util.Arrays; ` ` `  `class` `GFG ` `{ ` `     `  `// Recursive function to  ` `// return gcd of two nos ` `static` `int` `findgcd(``int` `a, ``int` `b)  ` `{  ` `    ``if` `(b == ``0``)  ` `        ``return` `a;  ` `    ``return` `findgcd(b, a % b);  ` `}  ` ` `  `// Function to find the minimum number ` `// of additional cuts required to make ` `// circle segments are equal sized ` `static` `int` `minimumCuts(``int` `a[], ``int` `n) ` `{ ` `    ``// Sort the array ` `    ``Arrays.sort(a); ` ` `  `    ``// Initial gcd value ` `    ``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``]; ` `    ``} ` ` `  `    ``// Inlcuding the last segment ` `    ``if` `(``360` `- s > ``0``) ` `        ``gcd = findgcd(gcd, ``360` `- s); ` ` `  `    ``return` `(``360` `/ gcd) - n; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int``[] arr = ``new` `int``[] { ``30``, ``60``, ``180` `}; ` ` `  `    ``int` `n = arr.length; ` ` `  `    ``System.out.println(minimumCuts(arr, n)); ` `} ` `} ` ` `  `// This code is contributed by mits `

## Python 3

 `# Python 3 program to find the minimum number ` `# of additional cuts required to make ` `# circle segments equal sized ` `  `  `import` `math ` `# Function to find the minimum number ` `# of additional cuts required to make ` `# circle segments are equal sized ` `def` `minimumCuts(a, n): ` `     `  `    ``# Sort the array ` `    ``a.sort() ` `  `  `    ``# Initial gcd value ` `    ``gcd ``=` `a[``1``] ``-` `a[``0``] ` `    ``s ``=` `gcd ` `  `  `    ``for` `i ``in` `range``(``2``,n) : ` `        ``gcd ``=` `math.gcd(gcd, a[i] ``-` `a[i ``-` `1``]) ` `        ``s ``+``=` `a[i] ``-` `a[i ``-` `1``] ` `  `  `    ``# Inlcuding the last segment ` `    ``if` `(``360` `-` `s > ``0``): ` `        ``gcd ``=` `math.gcd(gcd, ``360` `-` `s) ` `  `  `    ``return` `(``360` `/``/` `gcd) ``-` `n ` `  `  `# Driver code ` `if` `__name__ ``=``=` `"__main__"``: ` `    ``arr ``=` `[ ``30``, ``60``, ``180` `] ` `  `  `    ``n ``=` `len``(arr) ` `  `  `    ``print``(minimumCuts(arr, n)) `

## C#

 `// C# program to find the minimum ` `// number of additional cuts required ` `// to make circle segments equal sized ` ` `  `using` `System; ` `class` `GFG ` `{ ` `// Recursive function to ` `// return gcd of two nos ` `static` `int` `findgcd(``int` `a, ``int` `b) ` `{ ` `if` `(b == 0) ` `return` `a; ` ` `  `return` `findgcd(b, a % b); ` `} ` ` `  `// Function to find the minimum number ` `// of additional cuts required to make ` `// circle segments are equal sized ` `static` `int` `minimumCuts(``int` `[]a, ``int` `n) ` `{ ` `// Sort the array ` `Array.Sort(a); ` ` `  `// Initial gcd value ` `int` `gcd = a - a; ` `int` `s = gcd; ` ` `  `for` `(``int` `i = 2; i < n; i++) ` `{ ` `gcd = findgcd(gcd, a[i] - a[i - 1]); ` `s += a[i] - a[i - 1]; ` `} ` ` `  `// Inlcuding the last segment ` `if` `(360 - s > 0) ` `gcd = findgcd(gcd, 360 - s); ` ` `  `return` `(360 / gcd) - n; ` `} ` ` `  `// Driver Code ` `static` `void` `Main() ` `{ ` `int``[] arr = ``new` `int``[] { 30, 60, 180 }; ` `int` `n = arr.Length; ` ` `  `Console.WriteLine(minimumCuts(arr, n)); ` `} ` `// This code is contributed by ANKITRAI1 ` `} `

## PHP

 ` 0)  ` `        ``\$gcd` `= findgcd(``\$gcd``, 360 - ``\$s``);  ` `     `  `    ``return` `(360 / ``\$gcd``) - ``\$n``;  ` `}  ` ` `  `// Driver Code  ` `\$arr` `= ``array``(30, 60, 180);  ` `\$n` `= sizeof(``\$arr``);  ` ` `  `echo` `(minimumCuts(``\$arr``, ``\$n``));  ` ` `  `// This code is contributed by ajit ` `?> `

Output:

```9
``` My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.