Minimum Cuts to Divide a Circle - Problem

Imagine you're a pizza chef who needs to divide a circular pizza into n equal slices using the minimum number of cuts. But here's the catch - you can only make specific types of cuts!

Valid cuts in a circle can be:

  • Type 1: A straight line that touches two points on the edge of the circle and passes through its center (like a diameter)
  • Type 2: A straight line that touches one point on the edge of the circle and passes through its center (like a radius)

Given an integer n, return the minimum number of cuts needed to divide the circle into n equal slices.

Think about it: How do diameters and radii work together to create equal divisions? What's the mathematical relationship between the number of slices and the cuts needed?

Input & Output

example_1.py โ€” Single Slice
$ Input: n = 1
โ€บ Output: 0
๐Ÿ’ก Note: The circle is already one piece, so no cuts are needed.
example_2.py โ€” Two Equal Halves
$ Input: n = 2
โ€บ Output: 1
๐Ÿ’ก Note: One diameter cut divides the circle into 2 equal semicircles.
example_3.py โ€” Four Equal Quarters
$ Input: n = 4
โ€บ Output: 2
๐Ÿ’ก Note: Two perpendicular diameter cuts create 4 equal quarter-circles. This is more efficient than using 4 radius cuts.
example_4.py โ€” Odd Number of Slices
$ Input: n = 3
โ€บ Output: 3
๐Ÿ’ก Note: For 3 equal slices, we need 3 radius cuts from the center to the edge, creating 120ยฐ angles between each cut.

Constraints

  • 1 โ‰ค n โ‰ค 106
  • n is a positive integer
  • All slices must be equal in area and shape

Visualization

Tap to expand
Circle Cutting Patternsn=1: 0 cutsn=2: 1 cutn=4: 2 cutsn=6: 3 cutsn=5: 5 cuts
Understanding the Visualization
1
Base Cases
n=1 needs 0 cuts, n=2 needs 1 diameter cut
2
Even Numbers
For even n>2, use n/2 diameter cuts (each creates 2 pieces)
3
Odd Numbers
For odd n>2, use n radius cuts (each creates 1 piece from center)
Key Takeaway
๐ŸŽฏ Key Insight: Even numbers can use efficient diameter cuts (n/2), while odd numbers require individual radius cuts (n total)
Asked in
Google 12 Amazon 8 Meta 6 Apple 5
24.5K Views
Medium Frequency
~8 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen