# Pizza cut problem (Or Circle Division by Lines)

Given number of cuts, find the maximum number of possible pieces.

**Examples:**

Input : 2 Output : 4 Input : 3 Output : 7

This problem is nothing but The Lazy Caterer’s Problem and has below formula.

Maximum number of pieces = 1 + n*(n+1)/2

Refer this for proof.

## C++

`// C++ program to find maximum no of pieces ` `// by given number of cuts ` `#include<bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function for finding maximum pieces ` `// with n cuts. ` `int` `findMaximumPieces(` `int` `n) ` `{ ` ` ` `return` `1 + n*(n+1)/2; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `cout << findMaximumPieces(3); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find maximum no of ` `// pieces by given number of cuts ` `class` `GFG { ` ` ` ` ` `// Function for finding maximum pieces ` ` ` `// with n cuts. ` ` ` `static` `int` `findMaximumPieces(` `int` `n) ` ` ` `{ ` ` ` `return` `1` `+ n * (n + ` `1` `) / ` `2` `; ` ` ` `} ` ` ` ` ` `// Driver Program to test above function ` ` ` `public` `static` `void` `main(String arg[]) ` ` ` `{ ` ` ` ` ` `System.out.print(findMaximumPieces(` `3` `)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find maximum ` `# no. of pieces by given ` `# number of cuts ` ` ` `# Function for finding maximum ` `# pieces with n cuts. ` `def` `findMaximumPieces(n): ` ` ` `return` `int` `(` `1` `+` `n ` `*` `(n ` `+` `1` `) ` `/` `2` `) ` ` ` `# Driver code ` `print` `(findMaximumPieces(` `3` `)) ` ` ` `# This code is contributed 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find maximum no of ` `// pieces by given number of cuts ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function for finding maximum pieces ` ` ` `// with n cuts. ` ` ` `static` `int` `findMaximumPieces(` `int` `n) ` ` ` `{ ` ` ` `return` `1 + n * (n + 1) / 2; ` ` ` `} ` ` ` ` ` `// Driver Program to test above function ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `Console.Write(findMaximumPieces(3)); ` ` ` `} ` `} ` ` ` `// This code is contributed by nitin mittal. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find maximum ` `// no. of pieces by given ` `// number of cuts ` ` ` `// Function for finding maximum ` `// pieces with n cuts. ` `function` `findMaximumPieces(` `$n` `) ` `{ ` ` ` `return` `1 + ` `$n` `* (` `$n` `+ 1) / 2; ` `} ` ` ` `// Driver code ` `echo` `findMaximumPieces(3); ` ` ` `// This code is contributed by nitin mittal. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

7

This article is contributed by **DANISH_RAZA**. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Recommended Posts:

- Non-crossing lines to connect points in a circle
- Circle and Lattice Points
- Queries on count of points lie inside a circle
- Check whether a point exists in circle sector or not.
- Minimum lines to cover all points
- Program to find area of a circle
- Minimum revolutions to move center of a circle to a target
- Angular Sweep (Maximum points that can be enclosed in a circle of given radius)
- Number of Triangles that can be formed given a set of lines in Euclidean Plane
- Regular polygon using only 1s in a binary numbered circle
- Program for Point of Intersection of Two Lines
- Neighbors of a point on a circle using Bresenham's algorithm
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Check whether given circle resides in boundary maintained by two other circles
- Check if a line touches or intersects a circle