Background:
Given n
balls such that:
'a' balls are of colour GREEN
'b' balls are of colour BLUE
'c' balls are of colour RED
...
(of course a + b + c + ... = n
)
The number of permutations in which these balls can be arranged is given by:
perm = n! / (a! b! c! ..)
Question 1:
How can I 'elegantly' calculate perm
so as to avoid an integer overflow as as long as possible, and be sure that when I am done calculating, I either have the correct value of perm
, or I know that the final result will overflow?
Basically, I want to avoid using something like GNU GMP.
Optionally, Question 2: Is this a really bad idea, and should I just go ahead and use GMP?