Ctrl K

Equal Slices of a Round Cake

Easy
A round cake is cut with straight cuts, and every cut must pass through the center. A cut can be one of two kinds: - a **full** cut, from edge to edge through the center (along a diameter); - a **radial** cut, from the center to a single point on the edge. Given an integer slices, return the smallest number of cuts after which the cake is divided into exactly slices identical pieces.
Example 1
slices=6 → 3

Three cuts through the center, 60° apart, give six equal pieces.

Example 2
slices=5 → 5

An odd number of pieces cannot come from full cuts, so you need five radial cuts from the center to the edge.

Example 3
slices=1 → 0

The cake is already one piece, so no cuts are needed.

Constraints
  • 1 ≤ slices ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Triangle on the Board EasyDo Two Frames Overlap EasyShadows of Block Towers EasySurface of Cube Towers EasyHow a Rumor Spreads Easy
loading Python…
Input
slices=6
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 47 tests on the server, hidden ones included.