algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
2 shown · 0/261 solved

Minimum Cuts for Equal Shares

BronzeCommunity Beta
Asked atIDFC First Bank
Solve problem →
2000ms256MBAdded Aug 3, 2026Math & Number Theory

You are given n identical segments, each of length 1, and an integer m. The total length of all segments must be divided equally among m recipients, so each recipient receives pieces with a total length of exactly n / m. A single share may consist of several pieces, including pieces from different segments.

Each cut splits one piece into two shorter pieces at any point you choose. The segments start uncut.

Return the minimum number of cuts needed so that the resulting pieces can be partitioned into m groups of equal total length.

Examples

Example 1

Input: n = 2, m = 6
Output: 4
Explanation: Each share must have length 2/6 = 1/3. Cut each segment into three
pieces of length 1/3 (2 cuts per segment). The 6 pieces form the 6 equal shares.

Example 2

Input: n = 6, m = 4
Output: 2
Explanation: Each share must have length 6/4 = 3/2. Cut two segments in half
(1 cut each). Each recipient gets one whole segment plus one half segment.

Example 3

Input: n = 5, m = 5
Output: 0
Explanation: Each recipient gets one whole segment; no cuts are needed.

Constraints

  • 1≤1 \leq1≤ n ≤1000\leq 1000≤1000
  • 1≤1 \leq1≤ m ≤1000\leq 1000≤1000

Details

Solved by3 people
Time limit2000ms
Memory256MB
AddedAug 3, 20265 weeks ago
Math & Number Theory

More like this