# Minimum cuts required to divide the Circle into equal parts

Given an array *arr* which represents the different angles at which a circle is cut, the task is to determine the minimum number of more cuts required so that the circle is divided into equal parts.

**Note:** The array is already sorted in ascending order.

**Examples:**

Input:arr[] = {0, 90, 180, 270}

Output:0

No more cuts are required as the circle is already divided into four equal parts.

Input:arr[] = {90, 210}

Output:1

A single cut is required at 330 degree to divide the circle in three equal parts.

**Approach:** The idea is to calculate the Greatest Common Divisor of all the values obtained with the consecutive difference of two elements in the array in order to find the greatest (to reduce the number of cuts required) possible size for a part the circle can be divided into.

- First store the absolute difference of 1st two values of the array in a variable named
*factor = arr[1] – arr[0]*. - Now traverse the array from index
*2*to*N-1*and for every element update*factor*as*factor = gcd(factor, arr[i] – arr[i-1])*. - Then for the last element update
*factor = gcd(factor, 360 – arr[N-1] + arr[0])*. - Finally, the total cuts required will be
*(360 / factor) – N*.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the number of cuts ` `// required to divide a circle into equal parts ` `int` `Parts(` `int` `Arr[], ` `int` `N) ` `{ ` ` ` `int` `factor = Arr[1] - Arr[0]; ` ` ` `for` `(` `int` `i = 2; i < N; i++) { ` ` ` `factor = __gcd(factor, Arr[i] - Arr[i - 1]); ` ` ` `} ` ` ` ` ` `// Since last part is connected with the first ` ` ` `factor = __gcd(factor, 360 - Arr[N - 1] + Arr[0]); ` ` ` ` ` `int` `cuts = (360 / factor) - N; ` ` ` ` ` `return` `cuts; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `Arr[] = { 0, 1 }; ` ` ` `int` `N = ` `sizeof` `(Arr) / ` `sizeof` `(Arr[0]); ` ` ` ` ` `cout << Parts(Arr, N); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `import` `java.io.*; ` ` ` ` ` `class` `GFG { ` ` ` `// Recursive function to return gcd of a and b ` ` ` `static` `int` `__gcd(` `int` `a, ` `int` `b) ` ` ` `{ ` ` ` `// Everything divides 0 ` ` ` `if` `(a == ` `0` `) ` ` ` `return` `b; ` ` ` `if` `(b == ` `0` `) ` ` ` `return` `a; ` ` ` ` ` `// base case ` ` ` `if` `(a == b) ` ` ` `return` `a; ` ` ` ` ` `// a is greater ` ` ` `if` `(a > b) ` ` ` `return` `__gcd(a-b, b); ` ` ` `return` `__gcd(a, b-a); ` ` ` `} ` ` ` ` ` `// Function to return the number of cuts ` `// required to divide a circle into equal parts ` `static` `int` `Parts(` `int` `Arr[], ` `int` `N) ` `{ ` ` ` `int` `factor = Arr[` `1` `] - Arr[` `0` `]; ` ` ` `for` `(` `int` `i = ` `2` `; i < N; i++) { ` ` ` `factor = __gcd(factor, Arr[i] - Arr[i - ` `1` `]); ` ` ` `} ` ` ` ` ` `// Since last part is connected with the first ` ` ` `factor = __gcd(factor, ` `360` `- Arr[N - ` `1` `] + Arr[` `0` `]); ` ` ` ` ` `int` `cuts = (` `360` `/ factor) - N; ` ` ` ` ` `return` `cuts; ` `} ` ` ` `// Driver code ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `int` `Arr[] = { ` `0` `, ` `1` `}; ` ` ` `int` `N = Arr.length; ` ` ` ` ` `System.out.println( Parts(Arr, N)); ` ` ` `} ` `} ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation of ` `# above approach ` `import` `math ` ` ` `# Function to return the number ` `# of cuts required to divide a ` `# circle into equal parts ` `def` `Parts(Arr, N): ` ` ` ` ` `factor ` `=` `Arr[` `1` `] ` `-` `Arr[` `0` `] ` ` ` `for` `i ` `in` `range` `(` `2` `, N) : ` ` ` `factor ` `=` `math.gcd(factor, Arr[i] ` `-` ` ` `Arr[i ` `-` `1` `]) ` ` ` ` ` `# Since last part is connected ` ` ` `# with the first ` ` ` `factor ` `=` `math.gcd(factor, ` `360` `-` ` ` `Arr[N ` `-` `1` `] ` `+` `Arr[` `0` `]) ` ` ` ` ` `cuts ` `=` `(` `360` `/` `/` `factor) ` `-` `N ` ` ` ` ` `return` `cuts ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `Arr ` `=` `[ ` `0` `, ` `1` `] ` ` ` `N ` `=` `len` `(Arr) ` ` ` ` ` `print` `( Parts(Arr, N)) ` ` ` `# This code is contributed ` `# by ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` ` ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Recursive function to return gcd of a and b ` ` ` `static` `int` `__gcd(` `int` `a, ` `int` `b) ` ` ` `{ ` ` ` `// Everything divides 0 ` ` ` `if` `(a == 0) ` ` ` `return` `b; ` ` ` `if` `(b == 0) ` ` ` `return` `a; ` ` ` ` ` `// base case ` ` ` `if` `(a == b) ` ` ` `return` `a; ` ` ` ` ` `// a is greater ` ` ` `if` `(a > b) ` ` ` `return` `__gcd(a-b, b); ` ` ` `return` `__gcd(a, b-a); ` ` ` `} ` ` ` ` ` ` ` `// Function to return the number of cuts ` ` ` `// required to divide a circle into equal parts ` ` ` `static` `int` `Parts(` `int` `[]Arr, ` `int` `N) ` ` ` `{ ` ` ` `int` `factor = Arr[1] - Arr[0]; ` ` ` `for` `(` `int` `i = 2; i < N; i++) { ` ` ` `factor = __gcd(factor, Arr[i] - Arr[i - 1]); ` ` ` `} ` ` ` ` ` `// Since last part is connected with the first ` ` ` `factor = __gcd(factor, 360 - Arr[N - 1] + Arr[0]); ` ` ` ` ` `int` `cuts = (360 / factor) - N; ` ` ` ` ` `return` `cuts; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `[]Arr = { 0, 1 }; ` ` ` `int` `N = Arr.Length; ` ` ` `Console.WriteLine(Parts(Arr, N)); ` ` ` `} ` `} ` `// This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## PHP

$b)

return __gcd($a – $b, $b);

return __gcd($a, $b – $a);

}

// Function to return the number of cuts

function Parts($Arr, $N)

{

$factor = $Arr[1] – $Arr[0];

for ($i = 2; $i < $N; $i++)
{
$factor = __gcd($factor, $Arr[$i] -
$Arr[$i - 1]);
}
// Since last part is connected
// with the first
$factor = __gcd($factor, 360 -
$Arr[$N - 1] + $Arr[0]);
$cuts = (360 / $factor) - $N;
return $cuts;
}
// Driver code
$Arr = array( 0, 1 );
$N = sizeof($Arr);
echo (Parts($Arr, $N));
// This code is contributed by ajit.
?>

**Output:**

358

## Recommended Posts:

- Minimum number of cuts required to make circle segments equal sized
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Possible cuts of a number such that maximum parts are divisible by 3
- Count pieces of circle after N cuts
- Minimum operations required to make all the array elements equal
- Divide a big number into two parts that differ by k
- Divide a number into two parts such that sum of digits is maximum
- Divide number into two parts divisible by given numbers
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Program to find smallest difference of angles of two parts of a given circle
- Count ways to divide circle using N non-intersecting chords
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum
- Count number of ways to divide a number in 4 parts
- Check if any square (with one colored cell) can be divided into two equal parts

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.