Fast way to calculate n! mod m where m is prime?
n can be arbitrarily large Well, n can’t be arbitrarily large – if n >= m, then n! ≡ 0 (mod m) (because m is one of the factors, by the definition of factorial). Assuming n << m and you need an exact value, your algorithm can’t get any faster, to my knowledge. However, if … Read more