I have a vague memory of having done this some time ago but I don't remember the formula. What I need is all possible combinations of positive integers xi (i=1,..,k) that yield s when they are summed. For instance, for k=2 and s=2 there are the 3 combinations {0,2}, {1,1} and {2,0} the first number in a bracket representing x1 and the second x2. This can be done with the code
f[k_, s_] := Module[{c, x},
c = 0;
Do[
If[Sum[x[i], {i, 1, k}] == s, c++],
Evaluate[Apply[Sequence, Table[{x[i], 0, s}, {i, 1, k}]]]];
Return[c]]
But I need a fast function as I will calculate it for very big k and s. So this code is too slow. Do you remember the formula involving factorials? Or is there a Mathematica function that does this?