This problem is close to a standard problem: the number of ways of adding up non-negative integers to form a given fixed number $M$.
However in this case there are two constraints: 1) each of the summands has to be strictly greater than 0, and 2) the total number of summands is fixed at length $k$.
- for $k=1$ the answer is easy, 1
- for $k=2$ the answer is 2(sum from 1 to floor(M/2)).
So obviously that's enough to create a recursive algorithm that would allow one to calculate the answer to the question for any specific values of M and k, but I'm wondering if there is any closed form solution for arbitrary $M$ and $k$?
Another way to express this is the number of partitions of a non-empty set of finite cardinality $M$ where the number of parts (or blocks) in each partition is a fixed value $k$.