I was thinking a problem of finding the number of way to add M numbers, ranged 0 to K, to a give a desired sum. Doing some researches online, I find a way to use polynomial to achieve the goal. For example, suppose there are M numbers, each one ranged from 0 to K inclusive, if we consider the polynomial
$$(x^0 + x^1 + x^2 + \cdots + x^K)^M$$
the way to add those M numbers to get N is the coefficient of the term $x^N$, I also written a code to testify it. In this case, each number ranged 0 to K so there is duplicated numbers.
But I would like to extend the problem to the case with no duplicate numbers. I constrain that there are N different numbers $1, 2, \cdots, N$, pick M out of them ($M<N$) at a time, so all possible sums are
$$(1+2+\cdots+M), [2+\cdots+M+(M+1)], \cdots , [N+(N-1)+\cdots+(N-M+1)] $$
My question is how to figure out that how many way could that be from all possible M out of N numbers add up to above sum? I write a program to test that, when N, M are small (e.g. N=50, M=12), it is not that bad to enumerate all the cases, but if we increase N says to 100 or more, there are too many cases to retrieve. Any way like the polynomial method to do the trick quick?
I would like to add an example to clarify my questions. Let's say I have N=10 numbers, {1,2,3,4,5,6,7,8,9,10}, picking M=5 numbers out of them at a times (no duplicates), how many way I could pick 5 numbers out of those 10-number set such that the sum is 22?