It is well known that we easily can compute , say , $2^a\mod b$ for large integers $a,b$. We can use the repeated square method which gives a fast result even if $a,b$ have , say , $50$ decimal digits.
Is there a similar trick to compute $a!\mod b$ for , say , $50$ decimal-digit-numbers $a$ and $b$ ? We can assume that we know the factorization of $b$ , in fact , I am particular interested in the case that $b$ is prime. I would like to search prime factors of , say , $(18!)!-1$.
It is hopeless to apply $a-1$ multiplications modulo $b$. We can use Wilson's theorem , if $b-a$ is small , but I have little hope in the general case.
a! \bmod bfor a better spacing (the “binary mod” operator). – Martin R Jun 14 '24 at 21:40Since all factorials greater than 3 are divisible by 6, we have ((0 mod 6) mod (1 mod 6)) (1,5) (2,4)(3,3) (multiplier, remainder mod 6 left) etc.
– Roddy MacPhee Apr 01 '25 at 21:38