My roommate posed this problem to me about a week ago.
I posted it on math.stackexchange.com and got a response which led me to look up some numbers on the Online Encyclopedia for Integer Sequences (OEIS).
I just figured I'd pose the question here along with the answer now.
The answer is the following for m pens and n pieces per pen:
Bonus points to anyone who can explain it!