Pizza cut problem (Or Circle Division by Lines)

1

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

Examples:

Input  : 2
Output : 4

Input  : 3
Output : 7

pizza-cut

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++ 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;
}

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.

GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



1 Average Difficulty : 1/5.0
Based on 3 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.