I'd like to calculate Ps mod
K where Ps is the total number of unique permutations of elements in a set S. The problem is, the set S can have repetitions, so Ps = n! / (f1!f2! ... fn!), where n is the number of elements, and denominator the product of factorial of frequencies of each element in S.
The integer n can be assumed significantly large, say around 10^6
, and wouldn't likely fit in a uint64_t
. Is it even possible to calculate Ps mod
K without resorting to an arbitrary precision library? If yes, are there any fast methods to calculate it?