I need to find N! (mod 232-5) such that 0  N  264 for i cases, 0  i  1000 in 1 sec. Credits: https://dmoj.ca/problem/factorial2I am aware that I only have to handle 0  N  2  232-6 because once N  232-5, N!0 (mod 232-5) . A naive solution would take O((232-6)*1000). I have also tried using Wilsons Theorem and a naive solution, which would run in approximately O(4000000000*1000) time (Calculated from the highest point when O(N) intersects with O(232-5-N)log(N))). I cannot find a solution to this problem with a fast enough run time.Any help would be appreciated.
n! mod p Fast Factorial
mathematical programming