Use npm package `factorial` and simplify modulus