Number of ways to distribute n identical objects among r Identical groups such that each group gets at most Ceil(n/r) objects? Number of ways to distribute $n$ objects among $r$ groups such that each group gets at most $Ceil(n/r)$ objects?
I am looking for a formula which could give me the result and if possible a proof of why it is correct.
Thank you in advance.
 A: Rather than distribute objects between groups until there are $n$ objects, with a limit of $\lceil \frac nr\rceil$ objects per group, we can instead start by putting $\lceil \frac nr\rceil$ objects in each group, then remove objects from some groups until there are only $n$ objects left. We will have to remove $$k := r\left\lceil \frac nr\right\rceil - n = (-n) \bmod r$$ objects total.
So now we just have to count the number of ways to distribute $k$ objects between $r$ groups. Since $0\le k < r$, we don't have to worry about the upper limit of at most $r$ parts, so this is equivalent to finding $p(k)$: the number of partitions of $k$. (Wikipedia link)
I have made an assumption above that is not necessarily true: that any way of removing $k$ objects is valid. In fact, if $k > \lceil \frac nr \rceil$, then not all partitions of $k$ are allowed: for example, removing $k$ objects all from one group is not valid if there were fewer than $k$ objects in that group to start with. In this case, if $p_m(k)$ denotes the number of partitions of $k$ with a largest part of size $m$, then the number of valid partitions is $$\sum_{m=0}^{\lceil n/r \rceil} p_m(k) = p_{\lceil n/r \rceil}(k + \lceil \tfrac nr \rceil).$$
For large enough $n$, this restriction stops mattering, so the answer will become the periodic $p(k)$. For example, if we fix $r=5$, the answer for $n=1, 2, \dots$ is the sequence $$1,1,1,1,1,\;3,2,2,1,1,\;4,3,2,1,1,\;5,3,2,1,1,\dots$$ with the final block $5,3,2,1,1$ (which is $p(4), p(3), p(2), p(1), p(0)$) repeating forever.
