They are known as polynomial coefficients, which I will denote by m(a,b,...)
.
And you can efficiently compute them, avoiding overflow, using this identity (which should be pretty simple to prove):
m(a,b,c,...) = m(a-1,b,c,...) + m(a,b-1,c,...) + m(a,b,c-1,...) + ... m(0,0,0,...) = 1 // base case m(anything negative) = 0 // base case 2
Then it's just a matter of using recursion to compute the coefficients. Note that in order to avoid exponential runtimes, you need to either cache your results (to avoid recalculation) or use dynamic programming.
To check for overflow, just make sure the amounts will not be overflow.
And yes, it is a very bad idea to use arbitrary precision libraries to accomplish this simple task.
tskuzzy
source share