Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im trying to split (say) N pink, fluffy balls into M groups as evenly as possible.

Eg: 9 Balls and 4 groups, i'd have a result set of the form: {3,2,2,2}, where each value is indicating the size of each subset.

Can anyone help me understand how to write an equation or algorithm that would solve this problem?


share|cite|improve this question
Well, you say "divide": so look at division: what information does it tell you? Can you use that to help solve the problem? – Hurkyl Sep 20 '12 at 13:09
Aside: you probably didn't mean "result set", because "set" is usually used to refer to a collection that doesn't count repetition: the sets {3,2,2,2} and {3,2} are the same. – Hurkyl Sep 20 '12 at 13:10
Ah yes, its flooding back to me now. cheers – Larry B Sep 20 '12 at 13:16
up vote 2 down vote accepted

If you are given $N$ and $M,$ you put $\lfloor \frac NM \rfloor+1$ in $N \pmod M$ of the groups and $\lfloor \frac NM \rfloor$ in the rest.

share|cite|improve this answer
Thanks, was thinking along the lines of this. Think I was going for something like set all to n/m, then a for loop, 1 to (n Mod m) adding one. – Larry B Sep 20 '12 at 13:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.