I recently thought about the following problem, and I am very surprised that no one seemed to ask this question:
For a string, how many different permutations of this exist, modulo
?
I know the formula
where
is the length of the string, and
is the count of each character (given the alphabet size <img src = "/img/8448f6036f8b3c1845222e9d41e42efe.gif" alt = "K"> ). Thus, the string toffeewould have
various permutations.
But this no longer works when it
can be really big (say
), because the calculation
goes beyond the long long int, and using BigIntegers will be too slow. Is there a way to calculate this, for example,
or
time?
If I pre-processed the factorials from
to
, and my "strings" came in the form of an array of length
, where each element contains a counter for each letter, could it be calculated at
or
time?
Would thank for any help on this :)
source
share